iOS視頻播放
- MediaPlayer
- AVKit/AVFoudation
- ffmpeg
- WebView/WebServer
1.MediaPlayer
@available(iOS, introduced: 3.2, deprecated: 9.0, message: "Use AVPlayerViewController in AVKit.")
open class MPMoviePlayerViewController : UIViewController {
public init!(contentURL: URL!)
open var moviePlayer: MPMoviePlayerController! { get }
}
用法
import MediaPlayer
if let player = MPMoviePlayerViewController(contentURL: url) {
player.moviePlayer.prepareToPlay()
self.presentMoviePlayerViewControllerAnimated(player)
}
優(yōu)缺點(diǎn)
- 適用性強(qiáng)乌妙,簡(jiǎn)單
- 耦合度高供鸠,控件和功能難以自定義
- iOS 9.0之后不再支持
2.AVKit/AVFoundation
@available(iOS 8.0, *)
open class AVPlayerViewController : UIViewController {}
用法
Using AVPlayerViewController makes it easy for you to add media playback capabilities to your application matching the styling and features of the native system players. Since AVPlayerViewController is a system framework class, your playback applications automatically adopt the new aesthetics and features of future operating system updates without any additional work from you.
Important
Do not subclass AVPlayerViewController. Overriding this class’s methods is unsupported and results in undefined behavior.
import AVKit
import AVFoundation
let viewController = AVPlayerViewController()
let player = AVPlayer(url: url)
viewController.player = player
self.navigationController?.pushViewController(viewController, animated: true, completion: {
viewController.player?.play()
})
優(yōu)缺點(diǎn)
- iOS 8.0以上都可以使用
- 可以自定義控件选浑,也可以方便創(chuàng)建
- 方便創(chuàng)建時(shí),無(wú)法創(chuàng)建其子類(lèi)
- 基于AVKit/AVFoundation的庫(kù)有很多
3.ffmpeg
ijkPlayer
4.WebView
GCDWebServers