Solve by me using the following code. I am not happy with this as a
solution but it works

//so if I have an existing mediaplayer, which for note could be
playing something else
//I stop the existing playback, run the gc for good measure then
recreate the media player with the sound
//I want it to play

                if(mp != null) {
                        if(mp.isPlaying()) {
                                mp.stop();
                        }
                        mp = null;
                        Runtime.getRuntime().gc();
                        mp = MediaPlayer.create(this.getBaseContext(), 
R.raw.silentnight);
                        mp.start();
                } else {
                        mp = MediaPlayer.create(this.getBaseContext(), 
R.raw.silentnight);
                        mp.start();
                }

On Dec 8, 12:29 pm, akitto <[email protected]> wrote:
> I have two versions of the same application that starts by playing an
> mp3 from the res/raw/ directory, both versions of code are the same as
> far as the MediaPlayer is concerned and the code used. I get the
> following error in one version and it plays just I would expect in the
> other version. I am using 1.5 as my target. I get the same issue on my
> the devices (G1 and G2) as well as the emulator. I have read some
> other posts with the same issue and still am unable to resolve my own
> issue. For those who are going to come back with use MediaPLayer.create
> (context, id) I can not as I want to control what is being played
> without creating new instances of the player. It perplexes me that the
> same code works in another version of the same app that has no change
> in the code (in fact the alternative app just has a reduced number of
> images in the drawable folder).
>
> The error message also will occur if the file is not found by using
> mp.setDataSource("file");
>
> I am looking for an informed answer.
>
> Command PLAYER_SET_DATA_SOURCE completed with an error or info
> PVMFErrNotSupported
> ERROR/MediaPlayer(1583): error (1, -4)
> java.io.IOException: Prepare failed.: status=0x1
>
>         public void playSong() {
>                 if(mp == null) mp = new MediaPlayer();
>                 try {
>                         if(mp.isPlaying()) {
>                                 mp.stop();
>                         }
>                         FileDescriptor fd =  getResources().openRawResourceFd
> (R.raw.chime).getFileDescriptor();
>                         mp.reset();
>                         mp.setDataSource(fd);
>                         mp.prepare();
>                         if(sound)
>                                 mp.start();
>                 } catch (Exception e) {
>                         e.printStackTrace();
>                 }
>         }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to