Streaming .m3u8 using MPMoviePlayerController does not work

南楼画角 提交于 2019-12-23 04:53:25

问题


I used the example in how to play a local video and tried to modify for use on .m3u8 file. I am unable to make it work. I get a blank screen. I confirmed that the file was ok by testing on VLC. Any help would be appreciated.

Here is the code:

import UIKit
import MediaPlayer

class ViewController: UIViewController {
var moviePlayer : MPMoviePlayerController?
override func viewDidLoad() {
    super.viewDidLoad()
    playVideo()

    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

private func playVideo() {
    let path = "http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8"
    if let
        //path = NSBundle.mainBundle().pathForResource("movie", ofType:"m4v"),

        url = NSURL(fileURLWithPath: path),
        moviePlayer = MPMoviePlayerController(contentURL: url) {
            self.moviePlayer = moviePlayer
            moviePlayer.view.frame = self.view.bounds
            moviePlayer.prepareToPlay()
            moviePlayer.scalingMode = .AspectFill
            self.view.addSubview(moviePlayer.view)
    } else {
        debugPrintln("Ops, something wrong when playing .m3u8 file")
    }
}

}

回答1:


You've specified your url incorrectly. Change it to this:

url = NSURL(string:path)


来源:https://stackoverflow.com/questions/30670857/streaming-m3u8-using-mpmovieplayercontroller-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!