Android MediaPlayer does not play sound on some devices

I made a simple warning signal for my application. But the problem is that sound is played on some devices, but not on some others.

Sample code below:

public void audioPlayer() { // leshon tingull kur ka kolision //Armando 8/7/2013 MediaPlayer beep_alert = MediaPlayer.create(Maps.this,R.raw.double_beep); try { beep_alert.start(); } catch (Exception e) { e.printStackTrace(); } } 

There is no error shown, it just does not play, for example, nexus 4 , but it plays in the order of nexus 7 .

What is going wrong?

Double_beep is an mp3 file.

Thanks in advance...

+4
source share
2 answers

Make sure the volume is turned up, otherwise you will not hear anything.

In general, it is not recommended to increase the volume level programmatically without any user input - unless the volume is usually reduced by user action.

But here is how you can do it:

 AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); am.setStreamVolume(AudioManager.STREAM_MUSIC, am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0); 

This will be the maximum STREAM_MUSIC . There are many other ways to control / change the volume.

Read this to familiarize yourself with volume control: http://developer.android.com/training/managing-audio/volume-playback.html

+5
source

Your sound file does not contain special characters, such as _ (Underscore) and all. Try renaming to doubledeep . Nor should it begin with Capital Letter .

0
source

Source: https://habr.com/ru/post/1491154/


All Articles