0

私はムービーへのリンクを持つXMLフィードを含むアプリケーションを構築しています。ユーザーが画像をクリックするたびに再生したいと思います。デバイスのアプリケーションをテストするときのMPMoviePlayerサウンドのドロップ

私はMPMoviePlayerViewControllerを使用しています。シミュレータでアプリをテストすると、これまでのところ予想される結果が得られましたが、iPhoneでアプリをテストすると、プレイヤーは正しく再生されますが、サウンドは再生されません。

私は、いくつかの記事から、アプリケーションのパフォーマンスがシミュレータのパフォーマンスと大きく異なることをインターネットで見てきました。したがって、私はInstrumentsで「リーク」テストを行いました。映画を再生するたびに、いくつかのバイトがドロップされたり、リークされたりしていることがわかりました。突然の音の低下とは関係がありますか?もしそうなら、私はそれをどのように解決するでしょうか?

iPhoneで初めてのアプリをテストしているので、アプリがどれほどひどいことをしているのかとても驚いています。ムービープレイヤーパートのコードは次のとおりです。

#pragma mark Video Controls 
-(void)playVideo:(id)sender{ 
    moviePlaying=TRUE; 
    MPMoviePlayerViewController *playerViewController; 
    playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[data objectForKey:@"[att]url"]]]; 


    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:[playerViewController moviePlayer]]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidExitFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:[playerViewController moviePlayer]]; 
    MPMoviePlayerController *player = [[[MPMoviePlayerController alloc] init] autorelease]; 
    player = [playerViewController moviePlayer]; 

    [self.view addSubview:playerViewController.view]; 
    player.controlStyle = MPMovieControlStyleDefault; 
    player.shouldAutoplay = YES; 
    [player setFullscreen:YES animated:YES]; 
} 

- (void)moviePlayBackDidExitFullscreen:(NSNotification*)notification{ 
    MPMoviePlayerViewController *moviePlayer = [notification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer]; 

    [moviePlayer.view removeFromSuperview]; 
    [moviePlayer release]; 
} 
- (void)moviePlayBackDidFinish:(NSNotification*)notification { 
    MPMoviePlayerViewController *moviePlayer = [notification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer]; 

    moviePlaying=FALSE; 
    [moviePlayer.view removeFromSuperview]; 
    [moviePlayer release]; 
} 
#pragma mark VideoControls End 

私はあなたが問題を明るくすることを望みます。事前に

おかげで、

/Brinck10

+1

さて、私はそれが音が消えていたデバイスであることを知りました.-とにかく、私はアプリがデータを落とさないようにするために何ができるか知りたいと思います。 –

答えて

1

あなたはここにいくつかの非常に深刻な混乱を持っています。 MPMoviePlayerViewControllerとMPMoviePlayerControllerの両方を作成すべきではありません。どちらか一方を使用してください。そして、これらの線は意味をなさない:

MPMoviePlayerController *player = 
    [[[MPMoviePlayerController alloc] init] autorelease]; 
player = [playerViewController moviePlayer]; 

あなたはMPMoviePlayerControllerを作成し、プレイヤーに割り当てるが、その後、それを捨て、それを既存のMPMoviePlayerViewControllerののMoviePlayerを交換しています。

10ヤードを降りてパントしましょう。ムービー/ストリームサウンド/ MPMoviePlayerViewControllerを使うための簡単な方法です。これはビューコントローラですので、UIViewControllerを使用する場所に移動してください。

NSURL* m = // whatever; 
MPMoviePlayerViewController* mpvc = 
    [[MPMoviePlayerViewController alloc] initWithContentURL: m]; 
[self presentModalViewController:mpvc animated:YES]; 
[mpvc release]; 

をこれはMPMoviePlayerControllerとそのビューを作成し、唯一のフルスクリーンモードでのあなたのために全体のシェバングを提示:最も簡単なのはモーダル、それを示すことです。シンプルで簡単。ユーザーが「完了」をタップすると、モーダル表示が解除されます。

MPMoviePlayerControllerの使用は、より多くの関与があります。 UIViewControllerではありません。しかし、それは考えている。あなたは、ユーザーが何を見たい場合はあなたの仕事は、、、そのビューをつかむそれにフレームを与え、あなたのインターフェースにそれを固執することです:

NSURL* m = // whatever; 
MPMoviePlayerController* mp = 
    [[MPMoviePlayerController alloc] initWithContentURL:m]; 
self.mpc = mp; // property with retain policy 
[mp release]; 
self.mpc.view.frame = CGRectMake(10, 10, 300, 230); 
[self.view addSubview:self.mpc.view]; 

これはあなたのインターフェイスの映画のビューの一部になります。ムービーが実際のムービーである場合、フルスクリーンモードに切り替えるかどうか自由にユーザーに任せます。映画が単なる音であれば、ユーザーはそれを行う方法がありません。ストップ/ゴーボタンとスライダーがあります。

いずれにしても、ストーリーのどこかにMPMoviePlayerControllerがあるので、その通知に登録したり、再生/停止などを指示したりできます。しかし、2つの方法を混同したり混乱させたりしないでください。それはおそらくあなたのすべての問題の原因です。

+0

ありがとうMatt!私は週末にそれを調べてから戻ってきます。 –

関連する問題