我有一個splash_screen.mp4
文件。Mp4文件無法播放
這是我在.h
文件
@property AVPlayer * player;
@property AVPlayerLayer * playerLayer;
代碼.m
文件:
NSURL* mURL = [[NSBundle mainBundle] URLForResource:@"splash_screen" withExtension:@"mp4"];
self.player = [AVPlayer playerWithURL:mURL];
self.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
Float64 seconds = 1.5f;
CMTime targetTime = CMTimeMakeWithSeconds(seconds, NSEC_PER_SEC);
[self.player seekToTime:targetTime];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[self.player currentItem]];
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
self.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
self.playerLayer.needsDisplayOnBoundsChange = YES;
[self.playerLayer setFrame:[self.view bounds]];
[self.view.layer addSublayer:self.playerLayer];
self.view.layer.needsDisplayOnBoundsChange = YES;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
if (self.player) {
[self.player play];
}
});
在過去,我有一個.mov文件,並可以播放視頻文件,但現在我有一個.mp4文件,無法播放它。
測試模擬器上,視頻運行,但在設備上,它不運行。
它適合我。當你播放.mp4文件時,應用程序崩潰或不?如果崩潰,控制檯中的輸出是什麼? – ronan
@ronan,它不會崩潰。只是白色的空白屏幕。我調試,可以得到的網址,但我不知道爲什麼視頻不能播放。 – Khuong
檢查,它正確複製到複製束資源中。 –