0

i'm using the Vitamio bundle with success for streaming audio, but in some cases i have to play local audio. Inside MediaPlayerDemo_Audio activity the code says that in that case exists a bug if you want to play audio:

            case RESOURCES_AUDIO:
            /**
             * TODO: Upload a audio file to res/raw folder and provide its resid in
             * MediaPlayer.create() method.
             */
            //Bug need fixed
            mMediaPlayer = createMediaPlayer(this, R.raw.test_cbr);
            mMediaPlayer.start();

        }
    public MediaPlayer createMediaPlayer(Context context, int resid) {
    try {
        AssetFileDescriptor afd = context.getResources().openRawResourceFd(resid);
        MediaPlayer mp = new MediaPlayer(context);
        mp.setDataSource(afd.getFileDescriptor());
        afd.close();
        mp.prepare();
        return mp;
    } catch (IOException ex) {
        Log.d(TAG, "create failed:", ex);
        // fall through
    } catch (IllegalArgumentException ex) {
        Log.d(TAG, "create failed:", ex);
        // fall through
    } catch (SecurityException ex) {
        Log.d(TAG, "create failed:", ex);
        // fall through
    }
    return null;
}

The createMediaPlayer method crash when execute mMediaplayer.prepare() method and neither exists the Mediaplayer.create() method, so... What should i do? Thx in advance

Billyjoker
  • 729
  • 1
  • 10
  • 31

1 Answers1

0

Try adding this permission in the manifest

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
MetaSnarf
  • 5,857
  • 3
  • 25
  • 41