1
我正在嘗試創建一個將顯示視頻文件的AVPlayer。使用AVFoundation播放視頻時遇到問題
這是我到目前爲止的代碼:
- (IBAction) player {
NSURL* m = [[NSBundle mainBundle] URLForResource:@"Cache" withExtension:@"mov"];
AVURLAsset* asset = [AVURLAsset URLAssetWithURL:m options:nil];
AVPlayerItem* item = [AVPlayerItem playerItemWithAsset:asset];
AVPlayer* p = [AVPlayer playerWithPlayerItem:item];
self.player = p;
AVPlayerLayer* lay = [AVPlayerLayer playerLayerWithPlayer:p];
lay.frame = CGRectMake(10, 76, 303, 265);
[self.view.layer addSublayer:lay];
[p play];
}
我已經掛AVFoundation.framework
和CoreMedia.framework
,我已經進口<AVFoundation/AVFoundation.h>
。
首先,我得到一個錯誤,說property 'player' not found on object of type 'ViewController*
(線爲self.player = p;
)。我需要做些什麼才能使其運行?
此錯誤修復後,此代碼將正確顯示視頻?
在此先感謝
修復了這個問題。但是,視頻仍然不顯示。我試圖在模擬器中運行這個。任何其他想法? –