• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Play music synchronous using 3 MediaPlayer Objects on Android/Eclipse

 
andy schicki
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What i have: I have implemented three MediaPlayer.Objects in my App. All Three are created using a thread:


"simplified" Code in the Thread for creating:


As I read in several Tutorials the "prepare()" methode takes a little bit of time to finish. Therefore i implemented a "Waiting loop" which waits until all MPs are prepared and created.

When "prepare and create" are done i enable the Start button and i want to start all 3 Mediaplayers SIMULTANEOUSLY.

I again use a Thread for dooing so:



Code in the thread:


Please note that the code above is not the full code, but it should be enough to define my problem.

What i want, My problem:

All MPs should play their Music in Sync, unfortunately sometimes when i start the music, there is a time delay between them.

The MPs must start at the exact same time as the 3Audio-files must be played simultaneously (and exactly in sync)

What i have already tried:

+) using SoundPool: My Audio-files are to big(5Megabyte and larger) for SoundPool

+) seekTo(msec): i wanted to seek every MP to a Specific time: eg.: 0, but this did not solve the problem.

I hope somebody can help me!

Thanks in advance

android eclipse
 
Darryl Burke
Bartender
Posts: 5149
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
andy, welcome to the Ranch! Please BeForthrightWhenCrossPostingToOtherSites <- that's a link

http://stackoverflow.com/questions/30031373/play-music-synchronous-using-3-mediaplayer-objects-on-android-eclipse
 
andy schicki
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl thanks for the hint, i already updated my Post on stackoverflow.com so that everybody knows that i asked this on 2 sites to reach more Programmers.

 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Playing three tracks at the same time implies they will always be the same tracks, maybe? If so, you could just mix down the tracks and play one track. Or if it won't always be the same tracks maybe mix down the combinations you will use into single tracks? Android's audio isn't in the same league as the rest of it. Audio is its big hiccup. Which is kind of tragic.
 
andy schicki
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Guillermo:
I want to play three DIFFERENT tracks.
(same length but different "sounds", eg. Track1=vocals, Track2=drums,...)

Mix all the tracks and create one single track will not save my problem, because i want to mute and play all of the tracks as i want.

Example:

Play Track 1 + Play Track2 + play Track 3
---
Play Track 1 + Play Track2 + MUTE Track 3
---
Play Track 1 + MUTE Track2 + MUTE Track 3
--
Play Track 1 + MUTE Track2 + MUTE Track 3
--
and so on.

ANY suggestions :-/?
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so you need to be able to mute some of the tracks randomly. Is there any way to change the requirement so you don't have to do that? If not, what you need to write then is essentially a mixer. You might search on 'android mixer' and see what it turns up. Or if you can find a successful mixer in the playstore you might contact the author and say I'm not competing with you but I really need to know for my project how you start tracks at the same instant and keep them in synch.

P.S. remote chance if two tracks are enough. Handle them as a stereo pair where you can mute one but play the combination as mono. Probably not possible, but just saying.
 
andy schicki
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again for your reply.

Muting the tracks is a essential requirement, but thats not the big problem, i can mute the tracks by setting the volume to 0 if a button is pushed.

The main problem is that the MediaPlayer-Objects have a time delay when all three are started.

For better understanding:

I start all three MediaPlayer Objects at the same time (unfortunately they have a time delay and therefore they do not run synchronous).

Then i can set the volume of each player to 1 or 0 (this works without problems), but as they start with a little time delay the tracks are not in sync.
 
andy schicki
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PS:
i have read that maybe "JETPlayer" could help, but unfortunately i can not find a proper "Tutorial" which explains how to use it.
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
andy schicki wrote:Thanks again for your reply.

Muting the tracks is a essential requirement, but thats not the big problem, i can mute the tracks by setting the volume to 0 if a button is pushed.

The main problem is that the MediaPlayer-Objects have a time delay when all three are started.

For better understanding:

I start all three MediaPlayer Objects at the same time (unfortunately they have a time delay and therefore they do not run synchronous).

Then i can set the volume of each player to 1 or 0 (this works without problems), but as they start with a little time delay the tracks are not in sync.


I didn't misunderstand. Muting is the problem, not because it's hard, but because if it wasn't for needing to mute you could just use a mix down.
 
andy schicki
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okey, now i know what you mean ;-)
Yes then you are absolutely right, i guess MediaPlayer is not the right tool for this purpose.
 
andy schicki
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found a solution for that issue!!
--> Mediaplayer is not the right tool for this purpose!!
--> Better you use JETPlayer!
I have explained it here:

http://www.coderanch.com/t/649627/Android/Mobile/Android-JetPlayer#2998968
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic