iOS - 视频播放

iOS视频播放

  1. MediaPlayer
  2. AVKit/AVFoudation
  3. ffmpeg
  4. 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)
}

优缺点

  1. 适用性强,简单
  2. 耦合度高,控件和功能难以自定义
  3. 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()
    })

优缺点

  1. iOS 8.0以上都可以使用
  2. 可以自定义控件,也可以方便创建
  3. 方便创建时,无法创建其子类
  4. 基于AVKit/AVFoundation的库有很多

3.ffmpeg

ijkPlayer

4.WebView

GCDWebServers

你可能感兴趣的:(iOS - 视频播放)