的MPMoviePlayerController几秒钟后停止播放(MPMoviePlayerCont

2019-07-31 20:51发布

MPMoviePlayerController几秒钟后停止播放,这是我使用的代码:

NSString *urlAddress = @"http://67.159.28.74:8730";
NSURL *url = [NSURL URLWithString:urlAddress];

MPMoviePlayerController *player = [[MPMoviePlayerController alloc]initWithContentURL:url];
player.movieSourceType = MPMovieSourceTypeStreaming;

player.view.hidden = NO;
[self.view addSubview:player.view];
[player prepareToPlay];

if(player){
    [player play];
}

错误即时得到控制台是:

2012-09-23 18:07:56.618 Reader[696:c07] [MPAVController] Autoplay: Disabling autoplay for pause

2012-09-23 18:07:56.619 Reader[696:c07] [MPAVController] Autoplay: Disabling autoplay

2012-09-23 18:07:56.638 Reader[696:c07] [MPAVController] Autoplay: Disabling autoplay for pause

2012-09-23 18:07:56.638 Reader[696:c07] [MPAVController] Autoplay: Disabling autoplay

2012-09-23 18:07:56.643 Reader[696:c07] [MPAVController] Autoplay: Enabling autoplay

2012-09-23 18:07:56.645 Reader[696:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 0

2012-09-23 18:07:56.646 Reader[696:c07] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.

2012-09-23 18:07:56.648 Reader[696:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 0

2012-09-23 18:07:56.648 Reader[696:c07] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.

2012-09-23 18:07:56.650 Reader[696:c07] [MPAVController] Autoplay: Enabling autoplay

2012-09-23 18:07:56.652 Reader[696:c07] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0

2012-09-23 18:07:58.746 Reader[696:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 0

2012-09-23 18:07:58.746 Reader[696:c07] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.

2012-09-23 18:07:58.747 Reader[696:c07] [MPAVController] Autoplay: _streamLikelyToKeepUp: 0 -> 1

2012-09-23 18:07:58.748 Reader[696:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 1

2012-09-23 18:07:58.748 Reader[696:c07] [MPAVController] Autoplay: Enabling autoplay`

Answer 1:

解决它:

我把我的MPMoviePlayerController到属性:

//添加页眉

@property (strong,nonatomic) MPMoviePlayerController *myPlayer;

//在.m文件添加

- (IBAction)playStream:(id)sender {
    NSString *urlAddress = @"http://67.159.28.74:8730";
    NSURL *url = [NSURL URLWithString:urlAddress];

    MPMoviePlayerController *player = [[MPMoviePlayerController alloc]initWithContentURL:url];
    [player prepareToPlay];
    //Remember you have to add MediaPlayer.framework to your project
    /*[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:player];*/

    player.movieSourceType = MPMovieSourceTypeStreaming;



    player.view.hidden = YES;

    self.myPlayer = player;

    [self.view addSubview:self.myPlayer.view];


    if(player){
      [self.myPlayer play];
    }
}


Answer 2:

必须设置这样的类变量:

@property (nonatomic, retain) MPMoviePlayerController *moviePlayer;

我的代码如下所示:

NSURL *theUrl = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"mp4"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theUrl];
[moviePlayer prepareToPlay];
[moviePlayer.view setFrame: self.view.bounds];
moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[self.view addSubview: moviePlayer.view];
[moviePlayer play];

这工作适合我!



Answer 3:

上的Xcode 4.6.1它工作得很好。

但是,我有这个问题和Xcode 5!

但是,这种解决方案是非常有帮助:

“解决的办法是,玩家必须是一个实例变量或属性视图控制器的。也就是说,我们必须使用的MPMoviePlayerController实例

@属性(非原子,强)的MPMoviePlayerController * myMovieController;”

感谢作者非常感谢!

这是我的代码:

UIGraphicsBeginImageContext(CGSizeMake(1,1));

NSString *path = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:path];
self.moviePlayerView = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[self.moviePlayerView prepareToPlay];
[self.moviePlayerView.view setFrame:CGRectMake(0, 0, 320, self.view.frame.size.height/2)];
self.moviePlayerView.view.backgroundColor = [UIColor clearColor];
[self.moviePlayerView setContentURL:videoURL];

self.moviePlayerView.movieSourceType = MPMovieSourceTypeFile;
self.moviePlayerView.controlStyle = MPMovieControlStyleDefault;
[self.view addSubview:self.moviePlayerView.view];
self.moviePlayerView.shouldAutoplay = NO;
[self.moviePlayerView play];

UIGraphicsEndImageContext();


Answer 4:

你可以试试你实例化您的播放器后立即这样做: [player prepareToPlay]

更多资讯: iOS 6的流播放com.apple.coremedia.networkbuffering错误



Answer 5:

在iOS6的试试这个它的工作很适合我

NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"ddd" ofType:@"mp4"];
NSLog(@"%@",resourcePath);
NSURL *url = [NSURL fileURLWithPath:resourcePath];
NSLog(@"%@",url);
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
moviePlayer.view.frame = self.view.frame;
moviePlayer.moviePlayer.shouldAutoplay=YES;
moviePlayer.moviePlayer.controlStyle = MPMovieControlStyleNone;
[moviePlayer.moviePlayer setFullscreen:YES animated:YES];
[self.view addSubview:moviePlayer.view];
[moviePlayer.moviePlayer play];


Answer 6:

这里是你缺少的代码一个有趣的线。

根据苹果的文档

“当你添加一个电影播放器的看法到应用的视图层次,一定要尺寸框架正确,如下所示: http://tinyurl.com/9wgv9wc

MPMoviePlayerController *player =

    [[MPMoviePlayerController alloc] initWithContentURL: myURL];

[player prepareToPlay];

[player.view setFrame: myView.bounds];  // player's frame must match parent's

[myView addSubview: player.view];

// ...

[player play];

http://tinyurl.com/aeh9f84



Answer 7:

该解决方案是,玩家将必须是一个实例变量或属性的视图控制器。 即我们必须使用的MPMoviePlayerController实例

@属性(非原子,强)的MPMoviePlayerController * myMovieController;



文章来源: MPMoviePlayerController stops playing after a few seconds