For my application I need to play multiple tracks simultaneously and some kinf of listener to know when a track is finished.
SoundPool seems to be the obvious choice, but unfortunately I could't find a solution to get notified when a track ends.
I also thought about using multiple instances of Android's MediaPlayer, but I'm afraid of getting performance issues.
Are there any other options?
If you use MediaPlayer, you can use OnCompletionListener. It also has no problem of playing multiple tracks at the same time. Like gian1200 says. Try it, perhaps the performance is not really an issue.
Related
I have an application that so far recognizes some notes and I need to play them, but I need them in different duration.
I was thinking of having some mp3s with the notes, but I haven't found a way to play them a specific duration.
Can you help me with a solution for this issue?
You can use Timer Task for this work. It executes your code for specific limit of time.
I'm trying to make an app and I would liek to try to implement the optimal solution for multiple, simutaneously playing, programmatically selected sound effects.
I really appreciate the help.
Cheers
Well it depends:
Mediaplayer:
Not good for simultaneous playing (you need multiple MP objects), the response time and especially the prepare() methode take a lot of time.
Therefore synchronizing is quite impossible.
SoundPool:
Good for small MP3.files (size limt ~1mb, ~30sec)
Easy to implement
A lot faster than Mediaplayer. Mostly used for "sounds" and not a for complete "piece of music"
Jet Player/JET Creator
Used for MIDI files, quite difficult to install (you need python, wx python in order to use JET creator ...).
Very fast response, good for simultaneous playing of several tracks!
Any further questions? do not hesitate to ask!
best regards
I need to play sound effects in my game such as jump, failed, shot etc.
So for this purpose I have selected SoundPool class. But there were some times when it lagged.
So I wonder what is correct way to use this class. I have tried to use play method in new thread, it seems work better but I don't know if I am correct.
Please advice how to use object of this class correctly for better performance.
Best way to implement Sound / Music into your game is by using Service component. Read this answer here for an example.
I am currently trying to create an android app that plays a different sequence of sounds based on user input. Is there a simple way to play a sequence of sounds I have looked at mediaplayer and soundpool but it does not look like they where designed for sequential.
Thank you RandyFreak that is probably the better way. But I actually Ended up doing it a little differently.
I created a list of fileDescriptors pointing to sounds and added an oncomplete listener to mediaplayer. And every time the media player completed it's current sound it would play the first sound in the list and remove it from the list.
I came across this issue a few months ago.
How I overcame this was I created a different mediaplayer for each sound and played them in the order that I needed.
That would be the simplest method.
I hope this helps
RF
I apologize up-front if this is a really obvious question since I'm pretty sure I'm over-thinking it.
Anyway, I'm building a music player in Android which basically streams playlists from 8Tracks and, as my understanding is, the best-practice here would be using a foreground service. I've already built everything and it's completely functional sans service, however, I'm a little confused as to how to implement the service.
As is, I have my Player class, which controls the MediaPlayer, extending Service but I'm not quite sure where to progress from there. I've tried binding it to my Engine class which reconciles all the background work with the UI, however I keep getting a ServiceConnectionLeaked exception, and I'm fairly certain this is simply the wrong approach.
I would appreciate any help at all; really a nod in the right direction is all I need. Thanks for your time!
I think that you can directly control MediaPlayer without additional Player class. As I know MediaPlayer is already a service so you can use start and stop methods to play something.