简体   繁体   中英

Playing the audio file in android

In my application i want to play the audio through the MediaPlayer.

My code is

AssetFileDescriptor afd = getAssets().openFd("androidprojectsound.mp3");
MediaPlayer player= new MediaPlayer();
player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
player.prepare();
player.start();

In my logcat it shows the error message like

06-13 14:23:18.247: DEBUG/AudioSink(34): bufferCount (4) is too small and increased to 12
06-13 14:23:18.755: WARN/AudioFlinger(34): write blocked for 74 msecs, 1 delayed writes, thread 0xb3d8
06-13 14:59:34.125: ERROR/MP3Extractor(34): Unable to resync. Signalling end of stream.

I don't where iam doing wrong. Any suggestion wil be appreciated..

This means that your file is playing. You have to check it in a real Device. This is no issue. It will play fine in a Device. Try to run it in a Device.

Why don't you use play.setDataSource(FileDescriptor) instead of player.setDataSource(FileDescriptor,long,long)? From the code I've understood that you want to play the whole mp3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM