如何在iphone sdk 4.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅这个问题 -
播放视频在 Iphone 应用程序中从服务器获取文件
尝试以下代码,不要忘记添加 MediaPlayer.framework 并且必须导入
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>