Playing Hls (M3U8) in Cocoa Os X Avplayer - Swift

Playing HLS (m3u8) in Cocoa OS X AVPlayer - Swift

I tried to paste your code into a new OS X project (or macOS as we must start calling it now :))

When I launched the project I got this error in the console:

2016-06-21 09:09:27.860 Videoplayer[2494:169209] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

I don't know if you have the console enabled, it is the bottom part of your screen, provided you have the debug area enabled.

If you haven't got the debug area enabled, then you enable it in the top of Xcode

enable debug area

And then you need to make sure that you show the console as well, which is done in the bottom part of Xcode:

enable console

OK, now you can see the error, then how to fix it :)

This message basically tells you that Apple has blocked access to HTTP. This was introduced in OS X 10.11 and iOS 9, but can be disabled.

As it says in the console:

Temporary exceptions can be configured via your app's Info.plist file.

This means that you should add a new key to your info.plist file.

You can add it as "raw" plist data, which looks like this:

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

Or you can add it in the plist editor, where it looks like this:

editing plist

This question and the great answers describes the process better that I can

If I do this, I am able to get your code running and can watch the live stream, so I hope this helps you too.

play m3u8 file in iOS

I oppened the .m3u8 link in browser and the manifest that is being downloaded is wrong.
The manifest response is

#EXTM3U
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="English",DEFAULT=YES,AUTOSELECT=YES,FORCED=NO,LANGUAGE="en",URI=vtt_en.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=864000,SUBTITLES="subs"
hls-medium.m3u8

and the format the manifest must be something like this

Server .m3u8 file does not include any playlist

Also because you use Amazon you can check some examples from Amazon page

HLS video is not playing on simulator and real device

I was using HTTP URL which is not secured thus, it doesn't allow device or simulator to play it. I put an exception to allow insecure protocols which let the iOS to stream the HLS smoothly.

 <key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>

Sample Image

Playing HLS (.m3u8) using QTKit in MacOS 10.6.8

Ok, I've just found out that I've been accessing m3u8 files located locally in my directories.
Since this is HLS, one needs to have an http server for serving the playlist files.

My previous absoluteURL is
file://localhost/Users/guest/Desktop/Music/stream01/index.m3u8

QTKit works after putting up my own server and, changing the path of the playlist files to:
http://192.168.0.XX/stream01/index.m3u8

QTKit (adopted to Quick Time X Player) can:

  1. play .m3u8 files (provided they are served by an http server)

  2. play AES-128 encrypted .ts/.aac/.mp3 files in .m3u8 (video and audio)

It finally works! YEY!



Related Topics



Leave a reply



Submit