Don't you need to call prepare() before start()? The docs page has a very nice state chart with blocks and arrows, perhaps you could take a look.
http://developer.android.com/reference/android/media/MediaPlayer.html ("it's a nice red plane with white wings, looks like a giant Tylenol pill"... that chart is just as nice...) 07.01.2012 19:28 пользователь "Raghav Sood" <[email protected]> написал: > Mark, thanks for the reply. I am testing on a Nexus S (ICS 4.0.3 Stock) > and Lg Optimus One (2.3.3 Stock). > > I tried commenting out the setVolume() but it didn't help. The sound in > the level part of the game is working fine, but that is done through the > game engine. I am not using the game engine for loading the resources and > allowing the user to select a level, so that doesn't work here. > > I created a separate sample project that loaded the mp3 file on start and > played it and it works fine. I think that over here there might be some > problem due to the fact that I am calling the play() method from another > class. > > The LogCat shows no warnings related to this. > > Is there any other thing that could be causing this? > > Thanks > > On Sat, Jan 7, 2012 at 8:24 PM, Mark Murphy <[email protected]>wrote: > >> I'd temporarily comment out your setVolume() until you get the rest >> working. >> >> Make sure the emulator or device volume is set via the Settings app to >> an appropriate level. Ideally, then test your emulator or device with >> some other app, as I've had occasional problems getting the emulator >> output to work with my development machine. Also, testing with the MP3 >> file would indicate if there is something goofy with the file itself. >> >> Note that MediaPlayer tends not to raise exceptions but to log things >> at *warning* level in LogCat. >> >> FWIW, here is a sample app that also uses a raw resource for media >> playback: >> >> https://github.com/commonsguy/cw-advandroid/tree/master/Media/Audio >> >> In there, I use OGG. IIRC, OGG files worked better with looping way >> back when, though I don't know if that is now better with Stagefright >> than with the original OpenCORE media engine. >> >> On Sat, Jan 7, 2012 at 9:41 AM, Raghav Sood >> <[email protected]> wrote: >> > Hi all, >> > >> > I am working on a new game and am trying to add some background music. I >> > want this music to play across several activities, so I created a >> separate >> > class to handle it. The music is a single 32 second mp3 file. >> > >> > In my class, I get the music ready in the onCreate() like this: >> > >> > mPlayer = MediaPlayer.create(this, R.raw.gametheme); >> > >> > >> > I then have two methods to start and stop the music: >> > >> > >> > public static void play() { >> > >> > if(mSound == true) >> > >> > { >> > >> > soundPlaying = true; >> > >> > mPlayer.setLooping(true); >> > >> > mPlayer.setVolume(1.0f, 1.0f); >> > >> > mPlayer.start(); >> > >> > } >> > >> > } >> > >> > public static void stop() { >> > >> > if (soundPlaying == true) >> > >> > { >> > >> > mPlayer.stop(); >> > >> > } >> > >> > } >> > >> > >> > However, when I call BackSound.play() the music doesn't play. >> (BackSound is >> > the name of the class). There is no exception or error. It just doesn't >> > play. >> > >> > Any idea on how to do this? >> > >> > Thanks >> > -- >> > Raghav Sood >> > http://www.androidactivist.org/ - Author >> > http://www.appaholics.in/ - Founder >> > >> > -- >> > 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 >> >> >> >> -- >> Mark Murphy (a Commons Guy) >> http://commonsware.com | http://github.com/commonsguy >> http://commonsware.com/blog | http://twitter.com/commonsguy >> >> Android Training in NYC: http://marakana.com/training/android/ >> >> -- >> 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 > > > > > -- > Raghav Sood > http://www.androidactivist.org/ - Author > http://www.appaholics.in/ - Founder > > -- > 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 -- 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

