Using a webview to play an mp3- is it possible to keep it playing even when the screen is locked? - iphone

I have a portion of my app that simply launches a webview linked to an mp3 file- it opens the file and plays the audio. What I'd like to do is allow that audio to continue playing even if the user locks their iPhone. (As a side note, is there any way to replace the default Quicktime logo that appears in the player? Not that big a deal, just thought I'd ask =)
A third question- I also do the same thing (webview) with an .m3u linked file to stream live audio throughout the week- is it also possible to keep it playing when the iPhone is locked?
Thanks!!
Ben
Quick Edit: The same URLs work great in IOS Safari (locking and unlocking doesn't affect the audio. Just not in my app's webviews.

I did find my answer though, in case anyone comes here looking. Easiest thing in the world too- just add a row to the plist file labeled "Required Background Modes" and under that set item 0's value to "App plays audio". Voila!

Since the audio is in a UIWebView, I don't believe that you'd be able to play it in the background.
EDIT: I was wrong, adding "App Plays Audio" to the UIBackgroundModes will make it work even when audio is in a UIWebView.
Have you thought about just streaming the .mp3 file yourself? Should be easy enough and you'd be able to setup background streaming. To get you started, I'd check out Matt Gallagher's AudioStreamer class which easily allows you to stream .mp3 files and other audio files from the net: https://github.com/mattgallagher/AudioStreamer

Related

How do I enable background audio for an iPhone app

Currently I am designing an iOS application that will connect to a music stream through a network and play the audio to the user.
I have a simple setup with a button the enables the stream to start, and a UIwebview that connects to the stream. When I run the app (on an iPhone, NOT a simulator), the button works fine and launches the Quicktime player to begin playback for the audio. Pausing and playing from this screen works like a charm as well.
However I want my user to be able to start up the stream, turn the phone off (sleep the display) and continue to listen to the stream. However sleeping the display will fade out the audio until it stops playback.
I have tried to go into the app's PList file like a few others have told me to do online and added the field "Required background modes" and added App plays audio or streams audio/video using Airplay to the 0 array field and App downloads content from the network to the 1 array field.
("App plays audio" was not offered through auto-complete even though that was the phrase told to make the stream work. Instead I left it as "App plays audio or streams audio/video using Airplay" before trying it the other way to little more luck)
However neither of these are allowing the audio to continue to play when the display has been put to sleep. Can anyone offer up a suggestion as to how to make it work?
In Xcode 5.1, there's another place aside from the Plist that this needs to be set, Target -> Capabilities -> Background Modes... this seems to do more than just affect the plist, though I'm not absolutely sure of this.
Look here an sample code https://github.com/jsagorin/iOSBackgroundAudio
and here .. some explanations (how to Set UIBackgroundModes key in app-info.plist file, Set Audio Session Category , etc) http://www.sagorin.org/ios-playing-audio-in-background-audio/
Just make an entry in plist
Application does not require background mode and set its value to 'NO'
And add background Mode to VOIP

Is there an easy way to stream a m3u in iPhone?

I can have a UIWebView with the .m3u file opened, which will go to the webview with a play button displayed, and that automatically goes to the quicktime player and starts playing the stream. But when I press the done button, it goes back to the UIWebView with a little play button in the middle, and from there you can go back to the previous screen (it was selected from a tableview). So I just want it to automatically load the quicktime player in the view. How can I do that?
An m3u file is nothing more than a text file listing MP3 (and / or other format) digital audio files to be interpreted by player software as a series of audio files to be played in succession. So my best guess (I am about to implement this myself, so I'll find out soon if it actually works that way) at going about this is:
read in m3u file
parse for stream URLs and store these
choose / let user decide which one to play
Implement streaming player like explained here.
There is no step 5. I hope.

iPhone development - How to override microphone with contents of an audio file

Does anyone knows how to override the iPhone microphone with the content of an audio file?
Imagine a scenario where you are in a call and you wants to play some short audio to the other person hear it.
So, it would be necessary put the microphone (hardware) on hold, and write the content of the audio file into the mic buffer, using a delegate, after the audio finish the delegate would return the normal state, where the mic write on its buffer.
Is it possible?
Thanks!
PS: I am not sure about what tags to put for this question, so if someone knows which frameworks would be necessary to be used, or any tag suggestion, let me know that I change the them.
This isn't possible with the current SDK.
The best you can do is to get the user to put the phone into Speakerphone mode, then open your application and then play the sound at loud volume. The microphone would then pick it up.

Play audio and video at a same time in iPhone application

Is it possible to play audio and video file at a same time? I want to play different audio file and video file at a same time and also want control for both, so is it possible?
Sorry, not that I know of. The movie view automatically stops all audio files and takes up the whole screen, so you are forced to listen to the audio for the video.
If the audio is part of the video file, yes.
If it's an MP3 file or some other external type how are you planning on playing it? The phone might allow this to happen depending on what you're up too.
You might be in luck soon though...
Another helpful link is here.

How to get mp3 files to play in iPhone Safari web browser?

How can I get an MP3 audio file to play in iPhone Safari (OS 3.1)?
Currently, I am generating HTML e.g.
<img src="sound.png" alt="Play audio"/>
to play the file on clicking on the nested image. This works on Safari on OSX, but not on the iPhone. There, the content of the file is shown as text, but it does not appear to be a mime-type problem when checked with Live HTTP Headers from Firefox.
I have found approaches referenced here. These require the Safari Plugins setting to be on in the preferences, which is why it did not previously work for me.
I imagine your best bet is to invoke a quicktime object in your web page. For playing mp3 files, your best bet is to serve a Winamp .pls style playlist with mimetype audio/x-scpls that serves as a signpost to the mp3 files. Create an embedded quicktime object around it. Try the docs for quicktime:
http://www.apple.com/quicktime/tutorials/embed.html
If you manage to get it working, it will play in the QuickTime Application (Full screen).
The HTML5 sound API is not available in the current iPhone OS (3.XX), but in OS 4.XX it will be available (at least playing video without launching the full screen player)
Use the HTML5 audio tag with an mp3 in it. http://www.w3schools.com/tags/tag_audio.asp
Hey this simple html5 tag will do the trick
<audio src="someUrlToContent" controls="controls"> </audio>
what this does on the iPhone is bring up a play button that when pushed will go to quicktime.
on the iPad, a scrubbing play control will come up with a play/pause button. on both, the play control will size to the div they are in
As jottos points out, iPhone 3.x does not support HTML5 audio. If you want audio in the early versions of iPhone OS, you must use Quicktime specific code. This example actually embeds an entire playlist (not just a single song). If you want a single song, drop the qtnext parameters:
<embed
src="riding-with-the-king.jpg"
href="songs/01-riding-with-the-king.mp3"
artworkdata="riding-with-the-king.jpg"
type="audio/x-mp3"
target="myself"
scale="1"
controller="false"
loop="false"
autoplay="false"
allowembedtagoverrides="true"
height="500"
width="500"
qtnext1="<songs/02 Ten Long Years.mp3> T<myself> E<controller=true autoplay=true loop=false>"
qtnext2="<songs/03 Key to the Highway.mp3> T<myself>"
qtnext3="<songs/04 Marry You.mp3> T<myself>"
qtnext4="<songs/05 Three O'Clock Blues.mp3> T<myself>"
qtnext5="<songs/06 Help the Poor.mp3> T<myself>"
qtnext6="<songs/07 I Wanna Be.mp3> T<myself>"
qtnext7="<songs/08 Worried Life Blues.mp3> T<myself>"
qtnext8="<songs/09 Days of Old.mp3> T<myself>"
qtnext9="<songs/10 When My Heart Beats Like a Hammer.mp3> T<myself>"
qtnext10="<songs/11 Hold on I'm Coming.mp3> T<myself>"
qtnext11="<songs/12 Come Rain or Come Shine.mp3> T<myself>"
>
I had issues with mp3 on my local development system (Linux/apache2). I was only apple to play .OGG files in both Firefox(8) and Chrome(15) from the local file system. If I used the audio tag to link to a remote .MP3 or .OGG file either would work though? I am not sure why this is the case and since most of my local music files are MP3 it took me awhile to figure out that it was the file format that was the problem.