Play an audio file and return back to the page - iphone

in my iPhone app, I have an UIWebView with some simple HTML links to audio files.
When the user opens such an audio file, media player plays it an leaves my
UIWebView with this screen:
alt text http://img.skitch.com/20090622-rnx614kynh8faecjmuiyec159b.jpg
How do I dismiss it after the audio file was played?
I've searched for UIWebView's delegates without finding something useful.

Mike, I've found a solution: Create a HTML page and embed your audio file the follwing way:
<embed src=”http://www.mypage.com/test.wav”>
This gives you an embedded mini player.

No, you can't dismiss that properly, or at least I couldn't figure out how to do it. So I just used the movie player for all my audio and video. It's a little more complex but it is much more flexible.

Related

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

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

mp4 vs m3u8 format

I am trying to play a video in iPhone, which has m3u8 format. The video's link is parsed from an XML (so i cannot change it). I'm trying to play it with MoviePlayerController (set it on fullscreen, controlStyle is fullscreen too, set the presentModalViewController to the MoviePlayerController). After pressing the play button, the movie has only sound for a few seconds, no video screen, and the app crashes.
In this XML I have a different videolink, which contains mp4 format. Playing the video in the same mode (with MoviePlayerController and the settings...), it works fine. So: do you have any ideas what the problem is? If there is any encoding problems of m3u8? If it can be changed and how?
Thank you :)
Look the AVPlayerDemoPlaybackViewController class from this very useful open source control released by Peter Steinberger
https://github.com/steipete/PSPushPopPressView
Thanks again Peter!

UIWebView intercept "setting movie path:" from javascript audio player

In iOS 4, I've got a page loaded in a UIWebView with a javascript audio player. I did not create this player, it is owned by a third party, so I can't tinker with it. When I click the play button, I see an NSLog printout like the following:
setting movie path: http://data.myaudio.com/thefile.mp3
My question is, what is getting it's movie path set and how do I intercept it? The audio will continue to play until I create another UIWebView, or use the built in audio controls accessible by an iPhone home button double tap, or close the app. I can't intercept the path with shouldStartLoadWithRequest:, the javascript function audio.play() appears to call some built in player directly. I'd like to control where and how the audio is being played, but short of parsing the HTML for any <audio> tags, I can't figure out how to grab that path and point it somewhere other than the default.
UIWebView is essentially a wrapper for WebKit. Apple does not want you to touch anything more about it than is provided by the existing delegate methods.
That being said, you can modify the DOM of any loaded document by injecting JavaScript. This way you could also modify the audio.play to not do anything and instead get the URL to play with your own player that you can control.

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.

Movie Player in UIWebView

If I want to download an mp4 file, an iPhone movie player (MPMoviePlayerController) pops out and plays the video. My question is: can I get some kind of a message that it pops up or perhaps even prevent it from appearing?
One thing you could try is setting a delegate for your UIWebView and implementing -webView:shouldStartLoadWithRequest:navigationType:. Return NO if it's an mp4 (or mov) file.