Playlist file(m3u8) give another playlist file infinitely not giving any media file - iphone

I have a playlist file which give me another playlist file which also give me another playlist file, continously.
How can I play this playlist file? and Where can I found the source of video?
For example, I have a playlist file. That is
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=355670
http://slive.ytn.co.kr:1935/live/ylive_0624_1.sdp/playlist.m3u8?wowzasessionid=195968950
If I access to http://slive.ytn.co.kr:1935/live/ylive_0624_1.sdp/playlist.m3u8?wowzasessionid=195968950, it give me other playlist files.
#EXTM3U
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:894
#EXTINF:11,
media_894.ts?wowzasessionid=195968950
#EXTINF:10,
media_895.ts?wowzasessionid=195968950
#EXTINF:11,
media_896.ts?wowzasessionid=195968950
If I access to the results, it also give me playlist files.
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=373764
http://slive.ytn.co.kr:1935/live/ylive_0624_1.sdp/playlist.m3u8?wowzasessionid=1093961187
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=382539
http://slive.ytn.co.kr:1935/live/ylive_0624_1.sdp/playlist.m3u8?wowzasessionid=1566364859
etc...
Although I can play the url http://slive.ytn.co.kr:1935/live/ylive_0624_1.sdp/playlist.m3u8?wowzasessionid=195968950 in safari in my iphone, I want to play this url in my own iphone app.
How can I play m3u8 file extension by myself?

EDIT - May be a duplicate of this SO question but if you want to persist the file, you'll need to go the hard way listed below.
Easy way = Embed UIWebView in your app and initialize it with the url of the .m3u8 file. This will open up quicktime which understands m3u8 and it will play it as it downloads.
Hard way = manually create the request/responses for each part of the m3u8 session and then download each .ts file in turn from the playlist file. As you get each "chunk" of the video, write it to a file or memory, then append the next "chunk" after it. I've done this for a h.264 encoded .m4v file served as a m3u8 and it worked (my code is too ugly to paste) but the pseudocode is:
Fetch the m3u8, saving any cookies sent and any headers that may be important*
Parse the .m3u8 (the first file, with the #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=373764) and pull our the urls.
Fetch the playlist from one of the URLs in the .m3u8 file (being sure to keep any headers/cookies in the request that may be necessary)
Parse the playlist file, saving as much metadata as you need from the top part of the file, construct an absolute URL for each .ts path, then stuff it into an array.
Iterate over the array (again, being mindful of cookies/headers) and fetch the content of each .ts URL into a file.
Play the downloaded file with whichever Media Framework you choose (search SO for how to do this)
If you just need to play the files, go the easy route. If you need to persist them, you need to do the m3u8 dance.
*HTTP Scoop is invaluable for seeing how the m3u8 "protocol" works and for making sure you're request/response headers are accurate - http://tuffcode.com/
*I used vanilla NSURLConnection synchronous calls as my code was just a proof of concept, other network frameworks like AFNetworking will make this a lot easier.

Related

Download Result of Source Destination (Web Audio API)

I'm building a tool to edit audio with the Web Audio API.
Here is where I'm stuck:
...
source
.connect(gainNode)
.connect(analyser)
.connect(analyser2)
.connect(audioCtx.destination);
};
What I've written (which ends with the code above) successfully allows the user to upload a file, apply effects, and listen to it on play(). How would I then allow the user to click a button to export the results to a WAV file?
I've tried several methods online that have not worked for my use case.
Please let me know if more code is needed. Thank you for taking a look!
If you want a WAV file, I think you have to do that yourself. WAV files are quite simple. In this case, you'll need to add either a ScriptProcessorNode or AudioWorkletNode just before the destination to capture all the audio and convert it to a WAV file that can be downloaded.
If a compressed file is ok, you can look into MediaRecorder to save the data for you.
I ended up solving this by writing an entirely different script to download the file using OfflineAudioContext.
My original script plays the audio with effects, and the second script downloads it with the same effects. Now to figure out why there is latency on the effects while using OfflineAudioContext.

Prepending a header to a headerless .m4a file

I have some .m4a files that were captured from a radio broadcast stream. They are playable using mpd (an open source Music Playing Daemon for *nix), but iTunes won't open them (nor will several other music players that should be able to play .m4a files). When I looked at the file in hex format, and compared it to an .m4a file from iTunes, it appeared that the file from the broadcast stream did not have any header info.
So I figured I'd try prepending some header info to the file, to see if that would make it playable by these other players.
I've tried to read the technical doc about the .m4a file format to understand how the header is structured, but it's far too complex for me to follow (most of the doc is about the coding, which isn't pertinent to this). The header seems fairly simple, conceptually - I can see 4-character tags, variable length data, and there are presumably some length codes to allow these to be split apart. It doesn't seem to contain any significant data about the actual audio data (like its total length), making me hopeful that I might be able to get by by simply copying the header from an .m4a file and prepending it to these headerless files.
I'm unable, though, to manually parse (that is, reverse-engineer) the header in order to even experiment with this. Can someone describe how to identify a complete header at the front of a .m4a file?

Tag MP3 downloaded From Internet?

I am building an app with several podcasts. Each podcast gives the option to download the MP3 to the app. I have about 6 podcasts and would like to Tag each, so that when the archive view is clicked from each podcast, only archived files from that particular podcast show.
Is there someway that I can add a Tag or something to the downloaded mp3, and then in the archive, search only for mp3s with a tag related to that podcast?
BTW, I am using NSURLConnection to download each file
I think you may be looking at this in the wrong way.
Rather than tagging your downloaded files, you could set up a data structure to hold information about your files and use that to display your information.
For example. If I were doing this I would have a Core Data model that held information about the downloaded file, and tags, or sources, and I would store the path to that file in the database. That way, you can store whatever information you like about the downloaded file, and you can access it through it's path.

How to get Absolute path for a video using ALAssets Library?

Its simple, How can i get an absolute path for a video retrieved using ALAssets Library? I want to upload this video as file attachment using ASI framework.
It works if i use UIImagePickerViewController. But thats NOT an option any more. I also dont want to use NSData or copy-pasting video to temp file. Need a smart solution? Anybody ?
You can't get the absolute path (file system path) for a video you retrieved using the AssetsLibrary-Framework. The simple reason for that is that these files are outside your app's sandbox and you can't access them directly. You need to use the getBytes-Method of ALAssetsRepresentation to get the byte data of the video file. Most likely you will have to save this data to a temp file, before you can attach it to an email.
Cheers,
Hendrik
You can use ALAssetPropertyAssetURL. From documentation:
The key to retrieve a URL identifier for the asset.
The corresponding value is an NSURL object.
This URL is used by the library-change notifications to identify assets and asset groups. Only the ALAssetRepresentation and ALAssetsGroup classes support this property.
So, once you get ALAsset object you can get url like this:
asset.defaultRepresentation.url

Streaming and playing an MP3 stream. .mp3 URL format

I used the sample code from http://cocoawithlove.com/2008/09/streaming-and-playing-live-mp3-stream.html. it runs OK with default URL. But when I replace with my URL "http://dl.mp3.kapsule.info/fsfsdfdsfdserwrwq3/fc90613208cc3f16ae6d6ba05d21880c/4b5244f0/b/7e/b7e80afa18d06fdd3dd9f9fa44b51fc0.mp3?filename=Every-Day-I-Love-You.mp3", this app shows an message as "Audio not Found". But when I put my URL on Address Bar of Web Browser, I can download this .mp3 file.
really, I can't understand why it is?
pleased tell me!
Thank you very much
My guess would be that the app is designed to play a MP3 encoded audio stream with no limit in length (which is different from your ordinary music file). To set this up, you need a streaming server on the client side.
I think you can find out for sure by trying with a different radio station that transmits in MP3. If that works, it's most likely that your app doesn't like your file.
You should, as Vivek recommends, also try using a simpler download URL for your file, in case the App gets confused by the URL's length and/or structure.
As mentioned, this is due to the URL of the file. The AudioStreamer code specifically checks for the extension of the file and tries to figure out the audio type based on that. If you change that logic to handle your custom URLs, it will start working
So to point you in the right direction: open AudioStreamer.m and look for the references of
hintForFileExtension:
This function returns the type of file based on the extension. If you know the file type won't change (always mp3), the quick and dirty solution is to always assign mp3 type without any logic... like this:
err = AudioFileStreamOpen(self, MyPropertyListenerProc, MyPacketsProc, kAudioFileMP3Type, &audioFileStream);
Note: I've put kAudioFileMP3Type constant instead of calculated value
PS yes, it does work with static mp3 files, even though it's designed for streams and hence misses some of the functionality one would expect from a player that plays a static file on the server (caching, prefetching, proper seeking)
Thats because the default url directly points to a file in the webserver, whereas the the url you've mentioned is a HTTP (POST/GET) operation, which the application may not be designed to handle.
I suspect that your URL is one-time-use. When I try to visit it, I see 408 - Request Timeout.
Many links on mass file sharing websites are like this. If you could download the file directly, you wouldn't sit through a page of ads and premium account offers.
Try again with a file on a normal website, like this one.