Unexplained error from MediaPlayer


Last Updated:

  1. Sir^Knigget

    Sir^Knigget Member This Topic's Starter

    Joined:
    Sep 30, 2009
    Messages:
    11
    Likes Received:
    0
    My code tries to play an MP3 file from res/raw.

    Code (Text):
    1. FileDescriptor fd = appContext.getResources().openRawResourceFd(R.raw.ringtone)
    2.                     .getFileDescriptor();
    3. player = new MediaPlayer();
    4.             try
    5.             {
    6.                 player.setAudioStreamType(AudioManager.STREAM_RING);
    7.                 player.setDataSource(fd);
    8.                 player.prepare();          
    9.             }
    10.             catch (IllegalArgumentException e)
    11.             {
    12.                 // TODO Auto-generated catch block
    13.                 e.printStackTrace();
    14.                 player = null;
    15.                 return;
    16.             }
    17.             catch (IllegalStateException e)
    18.             {
    19.                 // TODO Auto-generated catch block
    20.                 e.printStackTrace();
    21.                 player = null;
    22.                 return;
    23.             }
    24.             catch (IOException e)
    25.             {
    26.                 // TODO Auto-generated catch block
    27.                 e.printStackTrace();
    28.                 player = null;
    29.                 return;
    30.             }
    31.  
    32.             player.setLooping(true);
    33.             player.start();
    The log shows:

    02-21 15:18:18.360: ERROR/PlayerDriver(51): Command PLAYER_SET_DATA_SOURCE completed with an error or info PVMFErrNotSupported
    02-21 15:18:18.380: ERROR/MediaPlayer(693): error (1, -4)
    02-21 15:18:18.390: WARN/PlayerDriver(51): PVMFInfoErrorHandlingComplete

    After player.prepare() is called.

    I really don't have a hint.
    I won't use MediaPlayer.create() because I need player.setAudioStreamType(AudioManager.STREAM_RING);

    Would appreciate any help on this...
     

    Advertisement
  2. jon21569

    jon21569 Member

    Joined:
    Aug 10, 2008
    Messages:
    23
    Likes Received:
    7
    I used the android.media.SoundPool object to play sounds. It worked for me with no issues. Here is an example of some of the code I used.

    private enum Sounds {
    WELCOME(R.raw.welcome),
    HELLO(R.raw.hello);

    private final int soundID;

    Sounds(int soundID) {
    this.soundID = soundID;
    }

    private int getSoundID() {
    return soundID;
    }
    };

    SoundPool soundPool;
    HashMap<Sounds, Integer> soundPoolMap;

    //Load Sounds
    soundPool = new SoundPool(4, AudioManager.STREAM_RING, 100);
    soundPoolMap = new HashMap<Sounds, Integer>();
    for ( Sounds sound : Sounds.values() ) {
    soundPoolMap.put(sound, soundPool.load(this, sound.getSoundID(), 1));
    }

    //Play Sound
    //-1 is loop forever
    final int soundID = soundPool.play(soundPoolMap.get(Sounds.WELCOME), 1.0f, 1.0f, 1, -1, 1f);

    //Stop Sound
    soundPool.stop(soundID);

    //Release Sounds
    soundPool.release();
    soundPool = null;
    soundPoolMap = null;
     

Share This Page

Loading...