如何在iphone sdk 4.0中播放视频?

发布于 2024-10-19 04:24:18 字数 871 浏览 2 评论 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 秒,然后自动关闭,而不播放文件。

我检查了视频文件,它是正确的,但它无法在 iphone sdk 4.0 中播放。

提前致谢。

I played video in iphone by using this code

-(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];  }

by using this code movie player opens for 1 second and then close automatically, without playing the file.

I checked the video file it is correct but it is not playing in iphone sdk 4.0.

Thanks in Advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

公布 2024-10-26 04:24:18

请参阅这个问题 -

播放视频在 Iphone 应用程序中从服务器获取文件

尝试以下代码,不要忘记添加 MediaPlayer.framework 并且必须导入


- (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];

}

please see this question-

Playing a video file from server in an Iphone app

trry out following code and don't forget to add MediaPlayer.framework and must import <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];

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文