iOS 中的原生播放器是 AVPlayer
与 Google 的 ExoPlayer 是 Android 中通常的默认设置相同(另请参阅下面评论中@Manuel 的出色注释),AvPlayer 是 iOS 中的通常默认设置,您可以使用它来播放流视频,通常在 HLS 中适用于 Apple 设备的 .m3u8 文件流格式。Android 设备的流通常是 DASH .mpd 文件流格式。
目前,Apple 还为包括 iOS 在内的设备添加了一个新的 UI 框架 - 如果您正在使用它,那么值得寻找一些 AVPlayer 集成的好例子,例如:
https://medium.com/@chris.mash/avplayer-swiftui-b87af6d0553
如果您使用的是更传统的 UIKit,那么 Apple 会提供一些您可以测试的简单示例,在下面的代码中替换您的测试流程(来自:https : //developer.apple.com/documentation/avfoundation/media_assets_playback_and_editing/creating_a_basic_video_player_ios_and_tvos?language=对象):
@IBAction func playVideo(_ sender: UIButton) {
//Substitute your video stream URL here to test
guard let url = URL(string: "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_adv_example_hevc/master.m3u8") else {
return
}
// Create an AVPlayer, passing it the HTTP Live Streaming URL.
let player = AVPlayer(url: url)
// Create a new AVPlayerViewController and pass it a reference to the player.
let controller = AVPlayerViewController()
controller.player = player
// Modally present the player and call the player's play() method when complete.
present(controller, animated: true) {
player.play()
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5891 次 |
| 最近记录: |