music playing on splashscreen problem.

  ... discussions about development with the GLES2 branch of AndEngine.

music playing on splashscreen problem.

Postby arkano » Fri Jul 06, 2012 2:19 pm

hi...i have a little problem.I am trying to play music when load a new scene an start this scene with music.im looking the music example, and made changes, but now when i start the aplication and the splash screen is running, my music is playing, no when i load the new scene.what im doing wrong??im using:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. private Music mMusic;
  3.  
  4. public EngineOptions onCreateEngineOptions()
  5.         {
  6.                 camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
  7.                 EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new FillResolutionPolicy(), camera);
  8.                 engineOptions.getAudioOptions().setNeedsMusic(true);
  9.                 return engineOptions;
  10.  
  11.  
  12.  
  13. public void loadResources()
  14.  
  15. MusicFactory.setAssetBasePath("mfx/");
  16.                 try {
  17.                         this.mMusic = MusicFactory.createMusicFromAsset(this.mEngine.getMusicManager(), this, "1-prometonocaer.ogg");
  18.                         this.mMusic.setLooping(true);
  19.                         } catch (final IOException e) {
  20.                         Debug.e(e);
  21.                         }
  22.  
  23. private void loadScenes()
  24.  
  25. tema1Scene = new Scene();
  26.                 mMusic.play();
  27.                 //Toast.makeText(this, "Toca la pantalla para pausar-continuar la musica.", Toast.LENGTH_LONG).show();
  28.                 tema1Scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));
  29.                
  30.                 SpriteBackground bg1 = new SpriteBackground(new Sprite(/*centerX, centerY*/0,0, temaunoBgTexture, this.getVertexBufferObjectManager()));
  31.                 tema1Scene.setBackground(bg1);
  32.                 tema1Scene.setOnSceneTouchListener(new IOnSceneTouchListener() {
  33.                
  34.                 @Override
  35.                 public boolean onSceneTouchEvent(Scene pScene, TouchEvent pTouchEvent)
  36.                 {
  37.                     if(pTouchEvent.getAction() == MotionEvent.ACTION_DOWN)
  38.                   {
  39.                         if(edenquatroActivity.this.mMusic.isPlaying()) {
  40.                                 edenquatroActivity.this.mMusic.pause();
  41.                         } else {
  42.                                         edenquatroActivity.this.mMusic.play();
  43.                                 }  
  44.                        
  45.                      }
  46.                     return true;
  47.                 }});
  48.  
  49.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

thanks for help
arkano
 
Posts: 37
Joined: Mon Jun 25, 2012 6:12 am

Re: music playing on splashscreen problem.

Postby andrewoid » Fri Jul 06, 2012 2:25 pm

Your code is written wierd, not sure where the curly brackets are placed in your methods loadResources and loadScenes.

First suspect would be the placement of your mMusic.play() you call it on line 26, after you create the Scene but not after your finished setting up the scene. I would instead call it after you have setup your onSceneTouchEvent.

If its STILL not playing correctly, call mMusic.pause() at the end of your loadResources().
andrewoid
 
Posts: 39
Joined: Fri Jun 29, 2012 1:22 pm

Re: music playing on splashscreen problem.

Postby arkano » Fri Jul 06, 2012 5:35 pm

thanks andrewoid....i try those two thinks.i add mmusic.pause in my load resources, and add mmusic.play after touch event, but now, my music dont sound.music is off when start splash screen, but when i start a new scene, the music is off too.the idea is : splashscreen /-menuscene with buttons.if click on a button, go to other scene/-start new scene with music playing/.
I have all working, except the music.im a little lost.
thanks again.
arkano
 
Posts: 37
Joined: Mon Jun 25, 2012 6:12 am

Re: music playing on splashscreen problem.

Postby andrewoid » Fri Jul 06, 2012 6:42 pm

I have not actually done music in my AndEngine game yet, Ill try it on Monday so if nobody gets back to you by then with an answer Ill try and help more. All I posted above was mostly guessing by logic.

One thing I spotted however was a weird method call in your TouchEvent:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. edenquatroActivity.this.mMusic.isPlaying()
  2.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


Now I dont know your class structure but this is a weird call in java anyway. Just change it to

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. mMusic.isPlaying()
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


If THAT doesn't fix it, then check if music has a method like .resume(). .play() may only just play from the start or mess up in some other way. I'm not sure.
andrewoid
 
Posts: 39
Joined: Fri Jun 29, 2012 1:22 pm

Re: music playing on splashscreen problem.

Postby arkano » Sat Jul 07, 2012 1:54 pm

thanks andrewoid.now its working.i change mMusic.play in loadScenes, and i use in bottonsprite.this button start the scene, then start the music too.But now i found other problem.i have in my code a key down event to back to my menuscene and stop the music.ok....if i use music.stop, the music dont sound anymore.if i use music.pause, works...but if i click again in the button and start the scene again, the music start in the pause point, not in the begin.i need to keep playing.
arkano
 
Posts: 37
Joined: Mon Jun 25, 2012 6:12 am

Re: music playing on splashscreen problem.

Postby OzLark » Sat Jul 07, 2012 2:05 pm

Use music.seekTo(0) before you resume :)
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Re: music playing on splashscreen problem.

Postby arkano » Sat Jul 07, 2012 4:37 pm

thanks ozlark, with .seekTo(0) works fine.......yuppiiiiiiii....jeje.Now i want to try with more scenes and more music files......thanks again....
arkano
 
Posts: 37
Joined: Mon Jun 25, 2012 6:12 am


Return to GLES2

Who is online

Users browsing this forum: fatal, Google [Bot], Hiteshc, Miyamoto, Navil, Yahoo [Bot] and 37 guests