I am trying to get a .m3u8 video stream to play within my app. I am programming in Swift for iOS 9 and 10.
Here is what I got so far:
import UIKit
import AVKit
import AVFoundation
import DynamicBlurView
class VideoPlayerViewController: AVPlayerViewController {
var urlString: String!
let blurView = DynamicBlurView()
override func viewDidLoad() {
super.viewDidLoad()
streamVideo()
}
func streamVideo() {
blurView.frame = view.frame
UIView.showProgressView(on: view, blurView: blurView)
let url = URL(string: urlString!)
let item = AVPlayerItem(url: url!)
player = AVPlayer(playerItem: item)
UIView.hideProgressView(on: view, blurView: blurView)
player?.play()
}
}
This should be simple, but I am getting errors and crashes all over the place.
This is the error I am getting:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x7b5b6810 {Error Domain=NSOSStatusErrorDomain Code=-12782 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-12782)}
Please help me!
EDIT:
Tried this suggestion with no luck. the app still crashes. The crash brings me to the AppDelegate if that info helps anyone.
import UIKit
import AVKit
import AVFoundation
import DynamicBlurView
class VideoPlayerViewController: AVPlayerViewController {
var urlString: String!
let blurView = DynamicBlurView()
override func viewDidLoad() {
super.viewDidLoad()
streamVideo()
}
func streamVideo() {
blurView.frame = view.frame
UIView.showProgressView(on: view, blurView: blurView)
let sampleURL = "https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8"
guard let url = URL(string: sampleURL) else { return }
let playerItem = AVPlayerItem(url: url)
player = AVPlayer(playerItem: playerItem)
player?.play()
UIView.hideProgressView(on: view, blurView: blurView)
}
}