视频输出不可见

时间:2012-10-08 13:55:49

标签: ios xcode ios-simulator media-player ios6

我正在创建一个可以在ios模拟器上显示预加载文件的应用程序。虽然显示屏显示在模拟器上,但我看不到视频,也听不到声音。

这是我的代码。

#import "BIDViewController.h"

@implementation BIDViewController
@synthesize moviePlayer;


-(IBAction)playMovie:(id)sender
{
NSString *url = [[NSBundle mainBundle]
                pathForResource:@"SwimGood" ofType:@"m4v"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc]
                                initWithContentURL:[NSURL fileURLWithPath:url]];
//Play partial screen.

player.view.frame = CGRectMake(64, 100, 200, 150);

[self.view addSubview: player.view];
[self.moviePlayer prepareToPlay];

[player play];
}

1 个答案:

答案 0 :(得分:0)

我像这样使用

  

NSString * videoFilepath = [[NSBundle mainBundle]   pathForResource:[tempDic objectForKey:@“VideoName”] ofType:@“mov”];

NSURL *url = [NSURL fileURLWithPath:videoFilepath];
     

MPMoviePlayerController * playerViewController = [[MPMoviePlayerController alloc] init];       playerViewController.view.frame = CGRectMake(6,5,308,202);

[playerViewController setContentURL:url];
playerViewController.controlStyle = MPMovieControlStyleNone;
[playerViewController prepareToPlay];
  [self.view addSubview:[playerViewController view]];

并且它工作正常..因此它可能是文件类型的问题。所以尽量使用.mov

并且不要忘记导入MediaPlayer / MediaPlayer.h 并添加MediaPlayer框架,它不存在于您的主包中。

祝你好运......