8

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`
4

7 回答 7

9

解决了它:

我把我的 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];
    }
}
于 2012-09-25T23:32:41.443 回答
8

你必须像这样设置一个类变量:

@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];

这对我来说很完美!

于 2013-09-26T15:00:54.590 回答
3

在 xCode 4.6.1 上它运行良好。

但是我在使用 xCode 5 时遇到了这个问题!

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

“解决方案是播放器必须是视图控制器的实例变量或属性。即我们必须使用 MPMoviePlayerController 的实例

@property (nonatomic,strong) 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();
于 2013-10-24T18:13:19.420 回答
1

您可以在实例化播放器后尝试执行此操作: [player prepareToPlay]

更多信息:iOS 6 流媒体播放器 com.apple.coremedia.networkbuffering 错误

于 2012-09-24T06:44:52.553 回答
1

试试这个,它在 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];
于 2012-09-28T07:42:20.093 回答
0

这是您缺少的有趣的代码行。

根据苹果的文件

" 当您将电影播放器​​的视图添加到应用程序的视图层次结构中时,请确保正确调整框架大小,如下所示: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

于 2012-11-10T06:58:38.093 回答
0

解决方案是播放器必须是视图控制器的实例变量或属性。即我们必须使用 MPMoviePlayerController 的实例

@property (nonatomic,strong) MPMoviePlayerController *myMovieController;

于 2013-05-22T07:19:17.873 回答