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 に答える
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 に答える
1

プレーヤーをインスタンス化した直後に、これを試すことができます。 [player prepareToPlay]

詳細はこちら: iOS 6 ストリーミング プレーヤー com.apple.coremedia.networkbuffering バグ

于 2012-09-24T06:44:52.553 に答える
0

これは、あなたが見逃している興味深いコード行です。

Appleのドキュメントによると

" ムービー プレーヤーのビューをアプリのビュー階層に追加するときは、次のようにフレームのサイズを正しく設定してください: 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 に答える