For what it is worth, we've had trouble with the media player since
1.6, where we would get failures if we used the media player rapidly
twice in succession to get ringtone titles.

Here's a post with more details:
http://groups.google.com/group/android-developers/browse_thread/thread/fee0d5edbe36ae0c/b2083a2b2688f001?lnk=gst&q=jarkman#b2083a2b2688f001

I think the media player takes some time to shut down and clean up,
and if you try to start it again during that time it just dies.

We fixed that problem in a roundabout way, by caching ringtone names.

Is it possible that the difference between your workign and non-
working applications was a timing difference ?

Richard


On Dec 14, 9:18 am, akitto <akitt...@googlemail.com> wrote:
> 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 <akitt...@googlemail.com> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to