【发布时间】:2017-05-12 13:22:08
【问题描述】:
两者都在 viewDidLoad() 中。 这个objective-c源文件有什么问题? 快速版本就像一个魅力...... Xcode 版本。 8.2 iOS 10
斯威夫特(好的):
let path : String = Bundle.main.path(forResource: "charlie", ofType: "mp4")!
let movieurl : URL = URL(fileURLWithPath: path)
let movie : AVPlayerViewController = AVPlayerViewController()
movie.view.frame = self.view.bounds
let player : AVPlayer = AVPlayer(url: movieurl)
movie.player = player
self.view.addSubview(movie.view)
player.play()
Objective-C(不显示/播放视频):
AVPlayerViewController* movie;
AVPlayer* player;
NSString *path = [[NSBundle mainBundle]
pathForResource:@"charlie" ofType:@"mp4"];
NSURL *url = [NSURL URLWithString:path] ;
movie = [[AVPlayerViewController alloc] init];
movie.view.frame = self.view.bounds;
player = [[AVPlayer alloc] initWithURL:url];
[movie setPlayer:player];
[self.view addSubview:movie.view];
[player play];
【问题讨论】:
-
代码可能没有找到视频。您是否尝试使用此 stackoverflow.com/questions/1949992/… 修复捆绑路径?
标签: ios objective-c avplayer avplayerviewcontroller