2

I'm developing a live streaming tv app using Swift but my channel file URL doesn't play.

My code:

override func viewDidLoad() {
    super.viewDidLoad()

    if let url = URL(string: "http://biwsat.com:8080/get.php?username=eYIvPmJeT2&password=3331jALAKY&type=m3u&output=ts"){
        let player = AVPlayer(url: url)
        let controller=AVPlayerViewController()
        controller.player=player
        controller.view.frame = self.view.frame
        self.view.addSubview(controller.view)
        self.addChildViewController(controller)
        player.play()
    }
}

If I use this link: http://devstreaming.apple.com/videos/wwdc/2016/102w0bsn0ge83qfv7za/102/hls_vod_mvp.m3u8 my player plays.

What should I do?

Brian
  • 14,610
  • 7
  • 35
  • 43
Celil Bozkurt
  • 1,693
  • 16
  • 18
  • Your video file is probably in a format that is not supported by the AVPlayer, I suggest you find the documentation to see what formats are supported. – EmilioPelaez Dec 07 '16 at 19:07

1 Answers1

0

For some reason AVPlayer doesn't accept files passed from a php Get function. It needs a straight link with .m3u8 extention. You have two choices:

1. Find a way to present the link so it ends in .m3u8
2. If you have access to editing the GET method and the server, check out Sommer's solution
3. If you don't have access to the Server, a huge workaround that worked for me is downloading the file provided from the link and then using an implementation of a HTTP server(e.g. GCDWebServer - is lightweight and still supported) to broadcast the file and access it as a URL in the AVPlayer. Apple doesn't allow playing local m3u/m3u8 files, so you must use HTTP Live Streaming (HLS), which basically means that the file must be stored on a server.
Example can be provided if needed.

Community
  • 1
  • 1
Phasebook
  • 104
  • 7