So I wanted to use MediaPlayers to play two different songs, and I
wanted to always start a new song from the beginning.

Apparently there's no way to restart a single MediaPlayer's track from
the beginning without reloading the file with setDataSource()...
intuitively, stop() would do it, but it apparently doesn't. And I also
can't find a way to use setDataSource() with a raw resource. I tried
musicLoop.setDataSource(_res.openRawResourceFd(R.raw.loop).getFileDescriptor());
where _res was gotten with context.getResources() or something like
that, and it compiled but didn't load the track.

I'm using a SoundPool for my game's SFX, but it takes too long to load
the longer music tracks, which is a shame. That class seemed designed
much more intelligently.

So after trying a whole lot of different ways (why is there no
getState() method for MediaPlayers? That would make dealing with the
awful state system a little better, at least), I was about to give up,
but I decided to try one more thing. So now I'm using just one
MediaPlayer for both tracks, and doing:

musicLoop.pause();
musicLoop = MediaPlayer.create(_context, R.raw.loop);
musicLoop.start();

Everything seems to be working fine, and I tried making this code (and
its twin for the other song) run over and over again, and there were
no crashes and it kept on playing the songs correctly... but this is
still nagging at me. What exactly does create() do? Am I leaving a
trail of unreferenced MediaPlayers behind whenever I use create() to
rebuild an existing MediaPlayer? If so, will the GC get them? (It
seems that it does, because I had an issue at first in another thread
where musicLoop.start() would be called during the creating, and then
two songs would play for a short time before the old one would
suddenly cut off.)

This could be unrelated, but I also just suddenly ran out of internal
flash space when I hadn't just installed anything. I'm not sending a
bunch of unreferenced MediaPlayers to a page file or anything, am I?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to