玩在iOS应用中的视频:音频,但没有图片 [英] Playing a video in iOS app: audio but no picture
问题描述
我想一个简短的视频在我的iphone应用程序播放。当我使用code以下时,我只能听到声音,看
该应用程序的常规视图。我希望视频这种观点之上玩。
我能做些什么呢?
一个NSBundle *包=一个NSBundle mainBundle]
* NSString的moviePath = [束pathForResource:@领头羊ofType:@MOV];
NSURL * movieURL = [[NSURL fileURLWithPath:moviePath]保留];
*的MPMoviePlayerController = theMovie [的MPMoviePlayerController页头] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie播放];
MPMoviePlayerViewController * moviePlayer = [[MPMoviePlayerViewController页头] initWithContentURL:movieURL];
[自presentMoviePlayerViewControllerAnimated:moviePlayer];
不要混淆的MPMoviePlayerController
和 MPMoviePlayerViewController
。当您使用的MPMoviePlayerController
使用它像这样(的通常用于iPad上的的嵌入式视频)
的MPMoviePlayerController *玩家=
[的MPMoviePlayerController页头] initWithContentURL:myURL];
[player.view SETFRAME:myView.bounds]; //玩家的框架必须父母的匹配
[MyView的addSubview:player.view];
// ...
[播放器播放];
当您使用 MPMoviePlayerViewController
然后present与 presentMoviePlayerViewControllerAnimated视频:
(通常为全屏视频的)。
i want a short video to play in my iphone app. When i use the code below, i only hear the audio and see the regular view of the app. I want the video to play on top of this view. What can i do about this?
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"LEADER" ofType:@"mov"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
Don't mix up MPMoviePlayerController
and MPMoviePlayerViewController
. When you use MPMoviePlayerController
use it like this (typically for embedded videos on the iPad):
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: player.view];
// ...
[player play];
When you use MPMoviePlayerViewController
then present the video with presentMoviePlayerViewControllerAnimated:
(typically for fullscreen videos).
这篇关于玩在iOS应用中的视频:音频,但没有图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!