视频无法在iPhone 5.0模拟器上播放 [英] Video won't play on iPhone 5.0 simulator

查看:53
本文介绍了视频无法在iPhone 5.0模拟器上播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不熟悉xCode编程,我从一个玩mp4 xCode的电子书教程中获得了此代码.

Im new to xCode programming, ive got this code from an ebook tutorial playing mp4 xCode.

通过按钮触发的功能

(IBAction)playMovie:(id)sender {
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"videoSample" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath]; 
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(moviePlaybackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];
[self.view addSubview:moviePlayerController.view]; 
moviePlayerController.fullscreen=YES;
[moviePlayerController play];
moviePlayerController.scalingMode = MPMovieScalingModeFill;
}

从播放电影功能中调用

(void)moviePlaybackComplete:(NSNotification *)notification{
MPMoviePlayerController *moviePlayerController = [notification
                                  object];
[[NSNotificationCenter defaultCenter]removeObserver:self
                                 name:MPMoviePlayerPlaybackDidFinishNotification
                               object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
}

构建之后,我没有任何错误和警告.我单击触发playMovie功能的按钮后,它只是输出一个空白屏幕.我混淆了谷歌它,仍然不知道如何解决问题.

Ive got no error and warning after i build it. it just output a blank screen after i click the button that triggers the playMovie function. Im confuse ive google it and still got no idea on how to solve the proble.

我正在使用xCode 4.2 iOS SDK 5.0

Im using xCode 4.2 iOS SDK 5.0

推荐答案

尝试此....将"example"替换为文件名,将"m4v"替换为文件类型,例如"mp4"(不是.mp4,也不要将.mp4位放在文件名中)

try this....replace "example" with the name of your file and "m4v" with the type of file e.g. "mp4" (not .mp4 and dont put the .mp4 bit in the name of the file)

-(IBAction)playVideo:(id)sender;
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"m4v"];


MPMoviePlayerViewController* tmpMoviePlayViewController=[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:path]];

if (tmpMoviePlayViewController) {

    tmpMoviePlayViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

    [self presentModalViewController:tmpMoviePlayViewController animated:YES];

    tmpMoviePlayViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

    [[NSNotificationCenter defaultCenter] addObserver:self

                                        selector:@selector(myMovieViewFinishedCallback:)

                                        name:MPMoviePlayerPlaybackDidFinishNotification

                                        object:tmpMoviePlayViewController];

    [tmpMoviePlayViewController.moviePlayer play];
}

}

-(void)myMovieFinishedCallback:(NSNotification*)theNotification
{
    MPMoviePlayerController *moviePlayer=[theNotification object];

[[NSNotificationCenter defaultCenter] removeObserver:self
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:moviePlayer];

[moviePlayer.view removeFromSuperview];

}

这篇关于视频无法在iPhone 5.0模拟器上播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆