MediaPlayer.setDataSource does not work in AMR audio file

01-15 00:57:08.660: WARN/System.err(25286): java.io.IOException: setDataSourceFD failed.: status=0x80000000 01-15 00:57:08.660: WARN/System.err(25286): at android.media.MediaPlayer.setDataSource(Native Method) 01-15 00:57:08.660: WARN/System.err(25286): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:854) ... 

... while trying to play a local AMR audio file from the application cache directory. This happens on HTC Magic, HTC Desire. The AMR audio file is recorded by SonyEricsson xperia x10 mini and downloaded from the Internet.

MediaPlayer is created as follows:

 MediaPlayer player = new MediaPlayer(); player.setOnCompletionListener(this); player.setOnErrorListener(this); player.setAudioStreamType(AudioManager.STREAM_MUSIC); try { FileInputStream fis = new FileInputStream(filePath); player.setDataSource(fis.getFD()); } catch (Exception e) { ... } 

Any ideas?

+4
source share
1 answer

I noticed that some setDataSource calls may fail on different devices (probably due to features in the platform of a particular player). For example, what fails with setDataSource( FileDescriptor ) may work fine with setDataSource( Context, Uri ) or setDataSource( String ) .

Try using one of the others and see if this works.

+1
source

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


All Articles