【问题标题】:how to use property Bool shouldautoplay MPMovieplayercontroller ios如何使用属性 Bool shouldautoplay MPMovieplayercontroller ios
【发布时间】:2014-07-14 08:49:27
【问题描述】:

我想在不点击播放按钮的情况下自动播放视频。 所以我找到了MPMovieplayerController“BOOl Shouldautoplay”的属性 但是不知道怎么用。

【问题讨论】:

标签: ios objective-c mpmovieplayercontroller


【解决方案1】:
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:fileName]];

    moviePlayer.initialPlaybackTime = 0;
    moviePlayer.view.frame = self.view.frame ;

    [self.view addSubview:moviePlayer.view] ;

    moviePlayer.shouldAutoplay = YES;
    [moviePlayer prepareToPlay];

希望对你有帮助

【讨论】:

  • 如果我使用 3rd 方媒体播放器怎么办??
  • 如果您使用的是第三方媒体播放器,那么您应该查看他们的文档。因为那里的 API 可以完全不同于 MPMoviePlayerController
  • 你必须在准备播放后使用[moviePlayer prepareToPlay];moviePlayer.shouldAutoplay = YES;
【解决方案2】:

这是另一种方式

-(void) mpVideo:(NSString *)fileName {

    videoFileName=fileName;
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:fileName]];

    moviePlayer.initialPlaybackTime = 0;
    moviePlayer.view.frame = self.view.frame ;
    [orientationHandler VideoStart];
    [self.view addSubview:moviePlayer.view] ;
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayer];
    moviePlayer.shouldAutoplay = NO;
    [moviePlayer prepareToPlay];
}

-(void)moviePlaybackDidFinish:(NSNotification *)notification {

    // your custom code which you want to play after the player did finish playing
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-01
    • 1970-01-01
    • 2011-06-19
    • 1970-01-01
    • 2015-09-18
    • 2015-05-31
    • 2011-12-23
    • 1970-01-01
    相关资源
    最近更新 更多