我在我的应用程序中有一个奇怪的问题。我试图在按下UI中的按钮后在iPhone上播放视频。我的问题是,它仅作为音频播放。和媒体播放器不显示,我只听到声音。 下面是我用来播放视频的方法的代码。在iPhone上播放视频
-(void) playMovieAtURL: (NSURL*) theURL {
MPMoviePlayerController* theMovie =
[[MPMoviePlayerController alloc] initWithContentURL: theURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
theMovie.movieControlMode = MPMovieControlModeDefault;
// Register for the playback finished notification
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(myMovieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: theMovie];
[theMovie play];
}
-(void) myMovieFinishedCallback: (NSNotification*) aNotification
{
MPMoviePlayerController* theMovie = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver: self
name: MPMoviePlayerPlaybackDidFinishNotification
object: theMovie];
[theMovie release];
}
,这是我如何调用以前的功能发挥设在我的资源视频
-(IBAction)play:(id)sender
{
NSString * url;
NSURL *theUrl;
NSBundle *bundle = [NSBundle mainBundle];
if (bundle)
{
NSString *moviePath = [bundle pathForResource:@"240_320_p" ofType:@"mp4"];
if (moviePath)
{
theUrl = [NSURL fileURLWithPath:moviePath];
}
}
[self playMovieAtURL:theUrl];
}
如何做到这一点?我试过 self.view = theMovie.view; 它的工作,但我认为这不是你的意思 我试过: [self.view addSubView:theMovie.view] ,但也导致声音只有 – belhaouary 2010-09-20 18:03:47
您是否在添加之前正确设置theMovie.view的框架属性它作为子视图? – 2010-09-20 19:41:54