Mp3 files in the android assets folder fail to play from APK

  ... in the unlikely case you discovered a bug, post it here.

Mp3 files in the android assets folder fail to play from APK

Postby timothyleerussell » Tue Feb 14, 2012 9:23 pm

Does anyone have any experience with this problem?

It is driving me crazy since this should work.

http://stackoverflow.com/questions/9124378/mp3-audio-in-the-android-assets-folder-fails-to-play-from-a-signed-and-zip-align
timothyleerussell
 
Posts: 19
Joined: Wed Sep 08, 2010 5:57 pm

Re: Mp3 files in the android assets folder fail to play from

Postby timothyleerussell » Tue Feb 21, 2012 5:46 am

So, I gave up on this problem and did the work to load the mp3 files from the "res/raw" directory. Frustrating that mp3 files in assets folder don't seem to work right though.

Based on that, I have a couple small suggestions about the file:

MusicFactory.java

While converting to using "res/raw", I had a problem with createMusicFromResource() failing due to .prepare() being called on twice. Once in MediaPlayer.create() and once with mediaPlayer.prepare().

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public static Music createMusicFromResource(final MusicManager pMusicManager, final Context pContext, final int pMusicResID) throws IOException {
  2.         final MediaPlayer mediaPlayer = MediaPlayer.create(pContext, pMusicResID);
  3.  
  4. //comment out this---------------------------------
  5.         //http://groups.google.com/group/android-developers/browse_thread/thread/260f2951d4a23445?fwc=1
  6.         //mediaPlayer.prepare();
  7. //comment out this---------------------------------
  8.  
  9.         final Music music = new Music(pMusicManager, mediaPlayer);
  10.         pMusicManager.add(music);
  11.  
  12.         return music;
  13.     }
  14.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


One other thing -- in createMusicFromAsset(), I'm not sure if assetFileDescriptor.close() should be explicitly called?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  public static Music createMusicFromAsset(final MusicManager pMusicManager, final Context pContext, final String pAssetPath) throws IOException {
  2.         final MediaPlayer mediaPlayer = new MediaPlayer();
  3.  
  4.         final AssetFileDescriptor assetFileDescritor = pContext.getAssets().openFd(MusicFactory.sAssetBasePath + pAssetPath);
  5.         mediaPlayer.setDataSource(assetFileDescritor.getFileDescriptor(), assetFileDescritor.getStartOffset(), assetFileDescritor.getLength());
  6.  
  7. //add this ? ---------------------------------------
  8.         //close the descriptor
  9.         assetFileDescritor.close();
  10. //add this ? ---------------------------------------
  11.  
  12.         mediaPlayer.prepare();
  13.  
  14.         final Music music = new Music(pMusicManager, mediaPlayer);
  15.         pMusicManager.add(music);
  16.  
  17.         return music;
  18.     }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
timothyleerussell
 
Posts: 19
Joined: Wed Sep 08, 2010 5:57 pm

Re: Mp3 files in the android assets folder fail to play from

Postby brigosx » Tue Jul 10, 2012 10:01 pm

I've just commented out the "mediaPlayer.prepare();" in the related loading methods inside the MusicFactory.java class and the problem resolved; at least when I've used the "createMusicFromResource" method.
brigosx
 
Posts: 1
Joined: Tue Jul 03, 2012 9:06 am


Return to Bugs

Who is online

Users browsing this forum: Exabot [Bot] and 3 guests