0

このコードを使用してiPhoneでビデオを再生しました

-(IBAction)btnNew_clicked:(id)sender {  

NSURL *url = [NSURL URLWithString:@"http://www.businessfactors.de/bfcms/images/stories/videos/defaultscreenvideos.mp4"];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[[mp moviePlayer] prepareToPlay];
[[mp moviePlayer] setShouldAutoplay:YES];
[[mp moviePlayer] setControlStyle:2];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self presentMoviePlayerViewControllerAnimated:mp];}

-(void)videoPlayBackDidFinish:(NSNotification*)notification  {       
[self dismissMoviePlayerViewControllerAnimated];  }

このコードを使用すると、ムービープレーヤーが1秒間開き、ファイルを再生せずに自動的に閉じます。

ビデオファイルが正しいことを確認しましたが、iphonesdk4.0で再生されていません。

前もって感謝します。

4

1 に答える 1

2

この質問を見てください-

Iphone アプリでサーバーからビデオ ファイルを再生する

次のコードを試してください。MediaPlayer.framework を追加することを忘れないでください。<MediaPlayer/MediaPlayer.h> をインポートする必要があります。


- (void)viewDidLoad {
    [super viewDidLoad];

    NSURL *url = [NSURL URLWithString:@"http://www.businessfactors.de/bfcms/images/stories/videos/defaultscreenvideos.mp4"];
    MPMoviePlayerController *player =[[MPMoviePlayerController alloc] initWithContentURL: url];
    [[player view] setFrame: [self.view bounds]];  // frame must match parent view
    [self.view addSubview: [player view]];
    [player play];

}
于 2011-02-25T05:51:12.340 に答える