I am downloading a .wav file from a server and storing it locally in the file system. Once the file has been downloaded I try and play the file using the AVPlayer.
The url of the file being stored is something like this:
/Users/user/Library/Developer/CoreSimulator/Devices/FC767376-76BC-4402-B51B-SDFS/data/Containers/Data/Application/FA18B9RE-8D6E-4553-0617-4A064478AFF4/Documents/voice/test.wav
I have gone through all the related questions and have checked that I am doing the following:
Keeping reference to the AVPlayer in the viewController
Setting the category on the AVAudioSession
Setting the AVAudioSession to active
using NSURL(fileURLWithPath:) to retrieve the file url
I have tried using AVAudioPlayer
I have also confirmed the url being set on the AVPlayer does infact contain the audio file.
I have generated a test project that reproduces this issues. It can be found at https://github.com/va3093/AVAudioTest
Is it the way that I am storing the file? Is there something wrong with the file formats?
It turns out that the webservice I was using to generate the audiofiles genertate .mp3 files while I was saving them as .wav. When I changed to .mp3 then the audio player started playing the audio files.
Related
I am playing a file using AVPlayer and it is working fine. What I am looking for is that when the application plays the file it should play as soon as some enough buffer available. Currently what I have noticed is that if the file is big it waits for longer time to start playing the file which means it waits until the file is loaded in the buffer or so.
Any thoughts?
First, thank you Paul, your hint helped.
I have resolved the issue as follow:
Instead of having the URL as the mp3 file; I have created a text file and called it audio.m3u then I have just wrote the url address of my mp3 file in the newly created file (the m3u). Then played the file (audio.m3u) in the AVPlayer.
thats all :)
I want to cache the HLS in the ts file.
Apple demo site use custom schema for this site.
https://developer.apple.com/library/ios/samplecode/sc1791/Introduction/Intro.html
This sample use custom schema. But it's use redirect for ts file.
I searched "How to play ts file using the cache in the AVPlayer". I found use redirect local proxy. But it method is prohibited to Apple that the move background.
https://developer.apple.com/library/ios/technotes/tn2277/_index.html#//apple_ref/doc/uid/DTS40010841-CH1-SUBSECTION2
Is it possible to start the ts file cached locally on the AVPlayer ?
As far as I know, Its not possible to play ts files directly using iOS Player (AVPlayer).
But there is a way to play it.
Download the .ts file and save it in app document directory.
Use this library Keemotion/TS2MP4 to
convert ts file to mp4 which can be played using AVPlayer.
Now you can either do it discreetly downloading -> convert -> play for each single file.
or You can download multiple -> convert them to one large mp4 file and play it.
I have a Cordova application that I use to be able to link to mp3 and mp4 files relatively using a src like so:
../../Documents/videos/video.mp4
I just now updated my Cordova application to the latest version and these relative URLs don't work so I've been expermenting with other solutions.
It looks like if I use the cordova.file.documentsDirectory (iOS only) variable I can link to them that way but when I save references to these files in the database the GUID of the application changes and the URL is no longer valid when the app is rebuilt and relaunched.
I tried using cdvfile://localhost/persistent/ but this seems to only work for images and not video or audio files using HTML5 audio and video tags for playback.
Ultimately I could save the files with a variable that gets replaced at run-time but this is obviously not the preferred "solution." Something like [documentsfolder]/videos/video.mp4
How can I link to a persistent file location and have it work with images, audio files, and video files?
I would love to use the cdvfile url but have it work with mp3 and mp4 files.
Thank you.
You should be able to access any resource [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:#"www/[your path]"]
I have a case where i need to get audio out from video file. Is this possible in iOS ??
I need only the output file as an audio any type. I have the video file in my documents directory which I record earlier in application.
1.Convert Video Reverse
2.Extract audio from a video file
3.Add Audio & Video Together
Download Code From Here
may be helpful to you.
Yes, it can be done. See Extract audio from video file for ideas.
Extracting is probably the more accurate term.
I have downloaded a mp3 file from a server successfully, but the problem I encountered is, I don't know how to play that file.. Should I use AVAudioPlayer or AudioQueue to play the file?? I will be appreciate if you could post some sample code here.
Both AVAudioPlayer and the Audio Queue API can be used to play MP3 files. The AVAudioPlayer is well documented and has a lot of sample code available. So why not give it try first and if that does not work, post a more specific question here.