I'm developing an IOS application which will download some videos to local so that users can watch those videos offline. But currently, a lot of videos are m3u and m3u8 format. As I know m3u and m3u8 is just a video list. So my question is how I can download the real video file into local and play them for m3u and m3u8 format.
Asked
Active
Viewed 1.2k times
1 Answers
2
First of all, m3u
or m3u8
is a playlist, does not contain music data.
To parse the file, you can follow the answer here. After you parsed the file, you can fetch the real media URL and load it with media player.
Reference of M3U file format in Wikipedia : http://en.wikipedia.org/wiki/M3U
UPDATE: Furthermore, another guy is doing similar thing. You can review his code here.
-
1Thanks for your quick update, but it seems you didn't answer my question. I want to know how to download m3u8 format video and play it on local. – user1340399 Dec 24 '12 at 04:57
-
You can use `NSURLConnection` to download file. See: http://stackoverflow.com/questions/2204010/how-to-use-nsurlrequest-nsurlconnection-to-download-an-mp3-file-to-app – Raptor Dec 24 '12 at 05:07
-
1Yes, I know how to download a file. But as you said, the m3u8 file is a playlist and the real media segment url is in it. How can I download the whole media file? – user1340399 Dec 24 '12 at 05:25
-
Download the m3u8 > Parse the file > get the media URL > Download the media using the media URL – Raptor Dec 24 '12 at 05:54
-
Shivan, thanks for your patience. Since it is very important for me, I'd like to clarify this with you. The following is a part of the m3u file.I can figure out the media url. After all media segments (.mp4.ts) are downloaded, how can I play them? Do I need to generate a my new m3u file to play them ? #EXTM3U #EXT-X-TARGETDURATION:25 #EXT-X-VERSION:3 #EXT-X-DISCONTINUITY #EXTINF:12, http://112.25.32.132/6777C380A074A78CDF04A6E64/03000811004C232BC7B8B20365E2F73663CAD1-2A48-99D6-F595-375BC7396F7F.mp4.ts?ts_start=0&ts_end=11&ts_seg_no=0&ts_keyframe=1 #EXTINF:17.48, – user1340399 Dec 24 '12 at 06:23
-
use `UIWebView` to load the m3u playlist is easier in your case, if your playlist contains mp4 segments. see this: http://stackoverflow.com/questions/11986313/http-live-streaming-for-iphone-and-why-we-use-m3u8-file – Raptor Dec 24 '12 at 06:26
-
@Raptor : How can I save the streaming video into gallery ? – Vineesh TP Nov 02 '17 at 10:21
-
1@VineeshTP Please ask in a new question, as this is not related to this old question. – Raptor Nov 03 '17 at 02:59
-
@Raptor : https://stackoverflow.com/questions/47068666/the-operation-couldn-t-be-completed-cocoa-error-1-phphotolibrary – Vineesh TP Nov 03 '17 at 03:07
-
@Raptor : if any updates, please answer. for above question, – Vineesh TP Nov 05 '17 at 14:18