Android MediaPlayer crashes on startup

I have a code that works very well on some devices (Samsung Galaxy S2, Acer A510), but on others (HTC One S) this causes MediaPlayer to crash. The code causing the problem:

if(file.exists()) {
        mediaPlayer = MediaPlayer.create(this, Uri.fromFile(file));
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.setVolume(100, 100);
        mediaPlayer.start();
    };

I tried to launch it in onPrepared callback or other ways to create mediaPlayer. They all work great on any device except HTC. Logcat error:

06-20 15:33:13.810: W/AudioSystem(6021): AudioFlinger server died!
06-20 15:33:13.810: W/IMediaDeathNotifier(6021): media server died
06-20 15:33:13.810: E/MediaPlayer(6021): error (100, 0)
06-20 15:33:13.810: E/MediaPlayer(6021): Mediaserver died in 16 state
06-20 15:33:13.820: I/ServiceManager(6021): Waiting for service media.audio_flinger...
06-20 15:33:14.821: E/MediaPlayer(6021): Error (100,0)

If anyone has any suggestions, I would appreciate it.

+5
source share

All Articles