How to keep specific time delay between the looping of an audio file in MediaPlayer in Android? - android-mediaplayer

I want to build an application for composing music. I have setup buttons that plays sounds but what i need here is to control the time delay after which the sound has to repeat. I have tried setLooping but it loops without any time delay.

you'll have to implement the looping by yourself with help of OnCompletionListener

Related

Audio player becomes unresponsive after paused for a minute

Building an audio streaming app using just_audio and audio_service. It uses an HLS url stream to get the audio. When audio is playing and the device is locked the controls will show on the lock screen and work properly using play/pause. However if the audio is paused for around a minute or longer the play button is tapped the lock screen controls will turn grey. I'll then open the app and try tapping play in the view and the Audio processing state will change to idle and nothing else happens.
I'm wonder if it has to do with the HLS stream at all. The amount of time that the player has to be paused before it "breaks" varies, but does seem to be consistent with the amount of audio that has buffered. So play/pause works fine if the amount of time the audio has been paused is less than the buffered amount, but if it passes then I encounter this issue.
As far as I can tell, nothing useful is logged at the time the audio player stops working, nor when tapping play/pause while in this state. I've tried to see if the OS kills the audio player maybe so I could re-init, but that doesn't seem to be the case either.
Figured this out, however, I'm not sure it's best solution.
One part is the provider for our HLS url for the live stream was able to increase the session timeout from 45 seconds to 5 minutes. There doesn't seem to be any negative behavior in doing this. It somehow prevents the background controls from breaking (greying out) when the audio has been paused for more then a minute (this varies and doesn't seem directly related to the session timeout, so maybe some magic iOS is doing too, who knows).
The other part is when a user locks their device and interacts with the background player something breaks to the point where if they go back into the app and try to switch the audio source something fails deep in the audio player. To "fix" this, when switching from the live stream to a non-HLS url I am now calling dispose on the audio player in the handler then re-initializing it.
This has solved my problem, but I think a better solution exists. For my specific case, using the SwitchAudioHandler may be that better solution, but I haven't had the time to try it.

play audio in background on intervals iOS

So I am working on an app that requires different audio files to be played using an NSTimer every X amount of time. Yes, it needs to play the audio in the background as well, but I have had inconsistent results trying to do so. I have searched the web thoroughly to find a solution to this problem, but I have had no luck.
I have enabled background modes and checked off item 0(audio) and made sure it was in my info.plist. I have set the "App does not run in background" key to NO in the info.plist. In the viewDidLoad method of the VC, I have set the AVAudioCategory to categoryPlayback and set the AVAudioSession to active. I have also moved these lines of code around in different places of the app to look for different results, and the best results I have gotten is that the app will continue to run in the background sometimes and at other times it will suspend.
Through all of my searching, I have seen forums explaining how to play audio in the background. However, I have not found any solutions to playing short audio files in the background intermittently on different scheduled intervals.
I know of at least one app in the App Store that is able to do this, and they use the ducking feature of AVFoundation to duck audio playing in the background(Im not sure if other frameworks are able to duck background audio, such as AudioToolbox, but I would like to have ducking enabled for my app).
If anyone knows of any legal solution for my problem, your assistance would be greatly appreciated.

WatchKit background processing

It may very well be a design issue but i am trying to build a watchOs 2 app that is essence a specialised timer that counts down to a specific time according to some parameters that user dials in.
Then I start a NSTimer to count down to this specified time the problem is that when the watch goes dark the timer suspends is there any way to stop this from happening or is there an alternative method.
Regards Christian
Use a local notification on the phone.

camera countdown timer issue

I have an app which record videos, now I can load the camera, record no problem, issue is i am using the function
[imagePickerController setVideoMaximumDuration:5];
property which limits the length of the video, what I'm wondering is if there a way this can be a countdown timer on the video screen.
Thanks
The two are unrelated.
Implement an onscreen countdown via whatever means you want and start it when you start the 5 second duration video recording. Then tear it down when the video stops recording.

iPhone SDK Question with Audio/Mic

I am trying to do an app, to where when it launches, it will detect audio, and then play it back automatically. NO BUTTONS, nothing to press. Just a picture of something then, it listens for audio, then plays it back. Similar to the Talking Carl app in the App Store. Any ideas/help? Would appreciate it, if i could use the code with IB.
Work through this example:
http://www.iphoneam.com/blog/index.php?title=using-the-iphone-to-record-audio-a-guide&more=1&c=1&tb=1&pb=1
And then you'll want to put the code for recording and playing back the audio in the viewDidLoad method of whichever view is your main view.
One thing you might also want to consider is how long you want it to record before it plays it back? And also, you'll want to stop recording once the sound starts playing... and also you'll want to start recording again once the sound STOPS playing.... all these things to think about and learn about :)