我想通過在應用程序中存儲視頻在本地在iPhone上播放視頻。 我該怎麼辦?如何在objective-c中爲iPhone本地播放視頻?
回答
要將視頻存儲在應用程序中,只需在構建中將其添加到複製文件階段即可。有關如何播放電影的示例,請查看媒體播放器文檔,尤其是MoviePlayer示例代碼。
NSString *path = [[NSBundle mainBundle] pathForResource:@"myVideo" ofType:@"mp4"];
MPMoviePlayerController *myPlayer = [[MPMoviePlayerController alloc] init];
myPlayer.shouldAutoplay = YES;
myPlayer.repeatMode = MPMovieRepeatModeOne;
myPlayer.fullscreen = YES;
myPlayer.movieSourceType = MPMovieSourceTypeFile;
myPlayer.scalingMode = MPMovieScalingModeAspectFit;
myPlayer.contentURL =[NSURL fileURLWithPath:path];
[self.view addSubview:myPlayer.view];
[myPlayer play];
試試下面的代碼:
-(IBAction)Videoplay_btn:(id)sender
{
NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"m4v"];
NSURL *streamURL = [NSURL fileURLWithPath:videoPath];
MPMoviePlayerController *moviplayer =[[MPMoviePlayerController alloc] initWithContentURL: streamURL];
[moviplayer prepareToPlay];
[moviplayer.view setFrame: self.view.bounds];
[self.view addSubview: moviplayer.view];
moviplayer.fullscreen = YES;
moviplayer.shouldAutoplay = YES;
moviplayer.repeatMode = MPMovieRepeatModeNone;
moviplayer.movieSourceType = MPMovieSourceTypeFile;
[moviplayer play];
}
有沒有更多使這更穩定?完成按鈕不起作用。當視頻結束時,整個應用程序被鎖定。從全屏縮小按鈕不起作用。我認爲這些都是MPMoviePlayerController類的所有實現細節。 – Praxiteles 2015-07-14 09:14:20
根據Apple的說法,不推薦使用MPMoviePlayerController for iOS9:https://developer.apple.com/library/prerelease/ios/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/index.html – Praxiteles 2015-07-14 09:16:35
FYI
的的MPMoviePlayerController類是正式的iOS 9 (該MPMoviePlayerViewController類也正式棄用。) 棄用播放視頻內容在iOS 9及更高版本中,改爲使用 AVPictureInPictureController或AVPlayerViewController類從 AVKit框架或WebKit的WKWebView類。
- 1. iPhone:如何在WebView中播放本地視頻?
- 2. 播放特定的本地IPhone視頻
- 3. 如何在iphone中播放視頻,xcode
- 4. 如何在iphone中播放視頻?
- 5. 如何在本地播放器中播放HTML 5視頻?
- 6. 播放本地視頻Android
- 7. 在iphone中播放視頻播放器中的視頻播放器
- 8. 在iPhone上播放視頻
- 9. 播放視頻流在iPhone
- 10. 視頻在陣列中如何播放該視頻。 iphone
- 11. 如何在iphone sdk中播放視頻時錄製視頻?
- 12. 在視頻播放中播放視頻
- 13. iPhone Dev:MediaPlayer在後續播放中不播放視頻(僅音頻)
- 14. 直播iPhone視頻播放iPhone SDK
- 15. 如何在視頻播放器中播放視頻
- 16. 因爲無論如何在iPhone的webview中播放flv視頻
- 17. youtube視頻在Android本地播放器
- 18. 在玻璃上播放本地視頻
- 19. 播放本地視頻在一個UIWebView
- 20. 如何從iPhone播放實況視頻
- 21. 如何在YouTube視頻播放器中播放YouTube視頻中的視頻android
- 22. 本地視頻在實際設備上播放Iphone
- 23. 如何在iPhone中一起播放音頻和視頻
- 24. 在iphone中播放視頻網址
- 25. 在iPhone 4.1中播放視頻文件
- 26. 在iphone應用中播放youtube視頻
- 27. iPhone框架視頻播放
- 28. iPhone視頻播放大小
- 29. iphone視頻播放編碼
- 30. iPhone UIWebview視頻播放4.0
當我使用這段代碼時什麼都沒有發生。沒有出現在屏幕上。沒有玩過。想法? – Praxiteles 2015-07-14 08:48:03
我們應該添加什麼項目? coreVideo ??? – Add080bbA 2016-04-12 18:43:36