• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Unexplained error from MediaPlayer

Sir^Knigget

Newbie
Sep 30, 2009
11
0
My code tries to play an MP3 file from res/raw.

Code:
FileDescriptor fd = appContext.getResources().openRawResourceFd(R.raw.ringtone)
					.getFileDescriptor();
player = new MediaPlayer();
			try
			{
				player.setAudioStreamType(AudioManager.STREAM_RING);
				player.setDataSource(fd);
				player.prepare();			
			}
			catch (IllegalArgumentException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
				player = null;
				return;
			}
			catch (IllegalStateException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
				player = null;
				return;
			}
			catch (IOException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
				player = null;
				return;
			}

			player.setLooping(true);
			player.start();

The log shows:

02-21 15:18:18.360: ERROR/PlayerDriver(51): Command PLAYER_SET_DATA_SOURCE completed with an error or info PVMFErrNotSupported
02-21 15:18:18.380: ERROR/MediaPlayer(693): error (1, -4)
02-21 15:18:18.390: WARN/PlayerDriver(51): PVMFInfoErrorHandlingComplete

After player.prepare() is called.

I really don't have a hint.
I won't use MediaPlayer.create() because I need player.setAudioStreamType(AudioManager.STREAM_RING);

Would appreciate any help on this...
 
I used the android.media.SoundPool object to play sounds. It worked for me with no issues. Here is an example of some of the code I used.

private enum Sounds {
WELCOME(R.raw.welcome),
HELLO(R.raw.hello);

private final int soundID;

Sounds(int soundID) {
this.soundID = soundID;
}

private int getSoundID() {
return soundID;
}
};

SoundPool soundPool;
HashMap<Sounds, Integer> soundPoolMap;

//Load Sounds
soundPool = new SoundPool(4, AudioManager.STREAM_RING, 100);
soundPoolMap = new HashMap<Sounds, Integer>();
for ( Sounds sound : Sounds.values() ) {
soundPoolMap.put(sound, soundPool.load(this, sound.getSoundID(), 1));
}

//Play Sound
//-1 is loop forever
final int soundID = soundPool.play(soundPoolMap.get(Sounds.WELCOME), 1.0f, 1.0f, 1, -1, 1f);

//Stop Sound
soundPool.stop(soundID);

//Release Sounds
soundPool.release();
soundPool = null;
soundPoolMap = null;
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones