2011-06-29 12 views
0

タブの1つでライブテレビチャンネルをストリーミングしているアプリがあります。私はMPMoviePlayerViewControllerを使用しています。私は自分のヘッダファイルに私のMPMoviePlayerViewControllerを宣言し、それを私の実装ファイルに合成しました。数秒後にMPMoviePlayerViewControllerが停止する

- (void)viewDidAppear:(BOOL)animated 
{ 
    NSURL *movieURL = [[NSURL alloc]initWithString:@"http://mysuperURL"]; 
    moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL]; 
    [self checkIt]; 
} 

そして、私のcheckIt機能

- (void) checkIt { 
    if ([[moviePlayerController moviePlayer] loadState] == MPMovieLoadStateUnknown) { // before you wreck yourself 
     [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(checkIt) userInfo:nil repeats:NO]; 
    } else { 
     [moviePlayerController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; 
     [self presentModalViewController:moviePlayerController animated:YES]; 
    } 
} 

ビデオが2秒後にフリーズするとアプリが応答を停止しかし:

は、ここに私のviewDidAppearです。

+0

? – Maulik

+0

なぜ[NSTimer scheduledTimerWithTimeInterval:0.1ターゲット:セルフセレクタ:@selector(checkIt)userInfo:nil repeats:NO];? – iMOBDEV

+0

checkitメソッドは、ムービーが再生可能な状態にあるかどうかを制御します。ムービーが再生可能な状態にない場合は、1秒(nstimer)待機し、再度checkitメソッドを呼び出します。 –

答えて

0

私の知る限りタイマーの使用については凍結しており、ストリーミングにも時間がかかります。

+0

私はタイマーで私のビューにプッシュしないので、タイマーだとは思わない。タイマーはムービーの準備が整うのを待つだけです。 –

2

現在の状態を手動でポーリングするのではなく、MPMoviePlayerNotificationsを使用する必要があります。例えば

- どこかにあなたがコードを初期化中:

[[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(MPMoviePlayerLoadStateDidChange:) 
               name:MPMoviePlayerLoadStateDidChangeNotification 
               object:nil]; 

今通知ハンドラを実装します。

- (void)MPMoviePlayerLoadStateDidChange:(NSNotification *)notification 
{ 
    NSLog(@"loadstate change: %Xh", movieController_.loadState);  
} 

そしてどこかdeinitializingコード内:

[[NSNotificationCenter defaultCenter] removeObserver:self 
                name:MPMoviePlayerLoadStateDidChangeNotification 
                object:nil]; 

はまたことに注意してくださいMPMoviePlayerController.loadStateはビットマップです - >値をマスクする必要がありますチェックしてください。例については

:checkIt方法は何をすべきか

if ((movieController_.loadState & MPMovieLoadStatePlayable) == MPMovieLoadStatePlayable) 
{ 
    NSLog(@"yay, it became playable"); 
} 
関連する問題