Find if an audio is currently playing - iphone

I need to find out if my program is currently playing any audio and in case it does, I want to stop the previous audio and start a new playback.
The property kAudioSessionProperty_OtherAudioIsPlaying always returns a 0 (probably only checks whether iPod music is playing)
There's another property kAudioQueueProperty_IsRunning but this always returns a 0 whether the audio is running or not. Can someone please tell me how I can find out if an audio is playing in my app or not.
Thanks.
Note: The class from which I invoke my streamer gets deallocated when I move back in the view hierarchy. So I do not have any way of accessing the AudioFileStreamID to know whether audio is playing. I need to use one of the properties provided by the SDK.

Found a workaround. Instead of creating the streamer object in a viewcontroller, I am using a reference in the appDelegate. This way I'll always have a live reference of the streamer class which I can access in any of the viewcontrollers to know whether audio is currently playing or not.

Related

MPMoviePlayerController - handle phone call

I'm using MPMoviePlayerController to play a video.
When a call comes, i want to pause and when he completes, i want to continue the video.
I couldn't find relevant solution in my search.
Is this something possible?
Its possible to handle the interruptions using AVAudioSessionDelegate "beginInterruption" and "endInterruption". But when I am setting the session to play back, my movie player sound is not heard at all.
Does any one know the solution?
There is a callEventHandler in Core Telephony framework. I hope, You could find what you want here.
We've to set the session active after endInterruption.

Movie is played with some delay after calling play on MPMoviePlayerController

I am developing an iPhone application in which I play videos using MPMoviePlayerController.
Sometimes, some of the videos don't play immediately after I call play on MPMoviePlayerController.
I have called prepareToPlay and in the notified method of MPMediaPlaybackIsPreparedToPlayDidChangeNotification, I am calling play on MPMoviePlayerController.
Could someone help in identifying the problem here?
Thanks,
Laxmilal
From my answer in a similar thread (reducing-the-initial-delay-when-playing-remote-video-content) - Note this fragment of the solution is valid for both, remote and local video content.
Use theMPMoviePlayerController.movieSourceTypeproperty when initializing your
player to cut down the media
recognition delay.
From the MPMoviePlayerController Class Reference:
The default value of this property is
MPMovieSourceTypeUnknown. This
property provides a clue to the
playback system as to how it should
download and buffer the movie content.
If you know the source type of the
movie, setting the value of this
property before playback begins can
improve the load times for the movie
content. If you do not set the source
type explicitly before playback, the
movie player controller must gather
this information, which might delay
playback.

Combine two audio files together and play them in iPhone

I do not want any code but want to get a reference about my question mentioned below...
There is background music available and there is recording option in my app...
Once I start recording , application records my sound and when play button clicks , It will play the recording along with the background music...
I had use this Link but can not get as I want...
I think there is a mechanism like merging two audio files and make it one before playing....
How can I achieve this by coding... Is there any reference link or any sample code available?
Thnx in advance...
Most people mistake the one instance of AVAudioPlayer as the unit that plays the sound directly, but it doesnt. Mixing is done by the OS, not by the instance of AVAudioPlayer.
With other words:
No one says you can't have more then one AVAudioPlayer.
Create one for you background and let it play. Create another instance of AVAudioPlayer for you recorded sound and let it play. Voila

UIAccelerometer is Shaking

I want a functionality in which i want to detect if my device is being shaked.The problem is i can detect the shake with didAccelerate method of UIAcceleratorDelegate , but i dont know how to detect if the device is still shaking. I want to play an audio file when the user shakes the device for first time,i have to check if the user is still shaking the device while playing the 1st audio file,if it is still being shaked, then i have to play another file.
See the sample project GLPaint from Apple which was found by visiting http://developer.apple.com/iphone and entering "shake" in the search box. Developer account not required.
You might consider writing a Method that runs in a separate thread that polls wether your device is being shaken every now and then and fire events that you handle somewhere else in your code (or instead of that, handle whatever you want to handle within the threads context itself, even tough i would not recommend doing that).
You just have to make sure, that your "shake-detektor"-thread exits at some point in time, you probably want to do that when the second audio file stopped playing. So your loop could test on that condition.
Hope I could help a bit.

MPMovie player how to get the amount of time played?

I was trying to go through the iPhone's sample code for mediaplayer.
I want to be able to capture the amount of time the media player has played the video. The duration at which the media player has stopped. Is there a method or property that will tell me the duration of play of the media??
Unfortunately the current API for MPMoviePlayerController allows basically no control. You can tell it to play and stop... otherwise where's a delegate method so you can be notified when the movie finishes playing and that's it, there's no additional controls. (a real bummer)
However, while we cant discuss the new 3.2 SDK yet, I'll give you a tip and say go look at the documentation of MPMoviePlayer in 3.2 and I think you'll be happy.
http://developer.apple.com/iphone/prerelease/library/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html
moviePlayer.currentPlaybackTime
It's not possible to do KVO on it but you could do like me and create an scheduledTimer which updates every second to check what the current playbacktime is and update your graphics accordingly :)
Yes, You can use the property "duration" defined by MPMediaPlayerController. Plese try it out and check the output. U can refer the here duration property