stop background music in a different scene in cocos2d - iphone

how to stop the background music in different scenes in cocos2d.Like in enabled sound option if we press "no" option the background music in another scene will stop and "yes" option will also do the same task. please help me i am new in cocos2d game development

Declare player and also set one variable or flag in app delegate class. By the help of this you can easily check it in any class of your application. So in scene where you want to stop your music, set your flag false and stop player....

Related

AVPlayer music stops when going to other view

im making a radio app and I have a swrevealviewcontroller with 3 views
picture:
enter image description here
this is the code of my first view, in trying to play music from a link with AVPlayer.
code:
I can start and stop the music from playing with this code but
when I open the menu and click on a menulink my music stops playing.
I cannot find a solution for this, I have already added the bacground mode in capability.
btw every view controller already has one class assigned to it.
can somoene pls help me
Your AVPlayer variable is located within the class. So when you leave that viewcontroller - that variable no longer exists. Make it global (outside of the class) and that should work just fine.
everything is working now by adding the player and the functions outside of the class, so now it's a global player with functions to start and play it

How to set the volume mute in movie player in iphone?

I am creating an app regarding movie player. In movie player I played videos. It worked fine but I want to mute the volume through coding. I want to set one button for volume mute. When I click the button it performs actions for mute. How can I proceed for this?
Hi there is no such mute option available. But you can set volume through codebase. Check this Apple documentation, it might be helpful to you:
http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMusicPlayerController_ClassReference/Reference/Reference.html

Is it possible to run an NSThread or NSTimer on iOS 4 device when it enters the background state?

I am writing an audio application which plays media items from the iPod music library using the iPod music player.
Now I know it is possible for the iPod to carry on playing when it is in the background, but I want to also run either a Thread or a Timer in the background where a selector method periodically checks the state of the music player so that the app can apply rules in order to apply delays between tracks, and automatically load up new media collections into the player all while in the background.
Is this possible?
If not, is there any other method for achieving this functionality?
The trick is to not use MPMusicPlayerController as when your app enters the background it actually relinquishes control to the iPod app (you can check this by closing your app and opening the iPod app).
For the music app I'm currently developing I've rolled my own music player using AVAudioSession and AVPlayer (not AVAudioPlayer). I've implemented a queue on the player, and a datasource (similar to UITableViewDatasource) which feeds the queue. All of this works eloquently whilst running in the background and has no association what ever with the iPod app (and as an added bonus you apps icon appears next to the remote controls on mulitasking bar).
If you developed something similar then when you ask your datasource for the next item in the queue, you could query your rule set and take a decision on what to do next.
Sure. You can do this in the application delegate's applicationDidEnterBackground:.
From the template:
If your application supports background execution, this method is
called instead of applicationWillTerminate: when the user quits.
Well yes and now, you can't use NSTimer because they are invalidated.
You can start a block of code to run via GCD to run in background which will have the max. execute time of 10 min.

How to keep MPMoviePlayerController open after movie ended?

If I use MPMoviePlayerController to play video in my iPhone app, it opens, loads the movie, plays it and then closes. Is it possible to force it to stay open after the movie finishes, so that user can replay it using its controls, instead of using controls in parent view? Also, is it possible to start MPMoviePlayerController in the paused mode?
thanks for any advice.
None of that is possible using the available API in the Pre-3.2 OS. One thing you could do is take a scerenshot of the last frame and stick that behind the movie so when it's done playing, it looks like it's still there, then just stick a button on it to replay. you could make an interface that looks/behaves similar to the standard movie player interface just for the play button if you need to.
For anyone stumbling over this now... There is a way to do this. Check out this question :)

AVAudioPlayer, Audio Session Categories and lock

I'm using AVAudioPlayer to play sounds on a game. When the user locks the device, I pause the game (and send it to a resume view) and want all the sounds to stop playing.
However, since the resume view is the same I use when loading a saved game, that view triggers a sound using an AVAudioPlayer. When it does so with the screen locked, the sound is audible, even though I'm setting the audio session to kAudioSessionCategory_SoloAmbientSound.
Does anyone know how to stop all sounds even if AVAudioPlayer play is called?
I tried calling this method:
AudioSessionSetActive(false)
but it didn't help.
Update: I'm currently setting the volume to 0.0 when the device is locked, however, I wanted to know if there was a built-in way via AudioSessions, etc.
Thank you
The best way I could find is to set the volume to 0 on lock events, and restore it when the device gets unlocked.