Kel*_*ort 1 macos video objective-c xcode5.1
我正在开发一个需要在应用程序中播放教程视频的mac应用程序.当用户按下应用程序上的按钮时,它应播放视频,这里是xcode 4.3的代码(与xcode 5.1不兼容)
@synthesize movieView;
-(IBAction)playVideo:(id)sender {
NSString *videoPath = [[NSBundle mainBundle] pathForResource:"video name" ofType:@"mp4";
NSURL *videoURL = [NSURL fileURLWithPath: videoPath];
NSError *error = nil;
NSDictionary *attrib = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES],
QTMovieOpenForPlaybackAttribute,
videoURL, QTMovieURLAttribute,
[NSNumber numberWithBool:YES],
QTMovieOpenAsyncRequiredAttribute, nil];
QTMovie *newMovie = [[QTMovie alloc] initWithAttributes: attrib error: &error];
[movieView setMovie:newMovie];
[movieView play:newMovie];
}
Run Code Online (Sandbox Code Playgroud)
我正在使用xcode 5.1 for osx 10.8
从OS X 10.7开始,Apple开始从QuickTime API(包括QTKit)过渡到AVFoundation.关于这种转变有一个详细的技术说明.
在现代Mac应用中播放视频的最简单方法是通过AVKit(自10.9开始提供).
要获得显示与您的应用捆绑在一起的视频的基本视图,您必须:
AVPlayerView在Interface Builder中拖动到一个窗口AVPlayer从您的包中加载视频资源的实例这是加载资产的代码:
NSURL* videoURL = [[NSBundle mainBundle] URLForResource:@"video name" withExtension:@"mp4"];
self.playerView.player = [AVPlayer playerWithURL:videoURL];
Run Code Online (Sandbox Code Playgroud)