質問

映画へのリンクを備えたXMLフィードを含むアプリケーションを構築しています。ユーザーが画像をクリックするたびに再生したいと思います。

そのために、私はmpmovieplayerviewcontrollerを使用しています。シミュレータでアプリをテストすることで、これまでのところ期待される結果が得られましたが、iPhoneでアプリをテストすると、プレーヤーは正しく再生されますが、音はありません。

インターネットを見て、いくつかの記事で、アプリのパフォーマンスはシミュレーターが提供するパフォーマンスとは大きく異なると言っていました。そのため、私は楽器で「リーク」テストを行いました。これは、映画の演奏を開始するたびに、いくつかのバイトが落とされたり漏れたりすることを教えてくれました。それは突然の音のドロップと関係があるでしょうか?もしそうなら、どうすればそれを解決しますか?

iPhoneでアプリをテストする最初の経験なので、アプリがどれほどひどく実行されているかを見て、かなりショックを受けました。これがMoviePlayer-Partのコードです。

#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

役に立ちましたか?

解決

ここでは非常に深刻な混乱があります。 mpmovieplayerviewcontrollerとmpmovieplayercontrollerの両方を作成しないでください。どちらか一方を使用します。そして、これらの行は意味がありません:

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

mpmovieplayercontrollerを作成し、プレーヤーに割り当ててから捨てて、既存のmpmovieplayerviewcontrollerのムービープレイヤーを交換します。

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つのアプローチを混乱させたり融合させたりしないでください。それはおそらくここであなたのすべての問題の原因です。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top