Stop Background music with a UIBarButtonItem and SoundEngine.h/

Discussion in 'iOS Development' started by DotSlashSlash, Oct 27, 2008.

  1. DotSlashSlash

    DotSlashSlash Active Member

    Joined:
    Feb 29, 2008
    Messages:
    1,134
    Likes Received:
    0
    Device:
    iPhone 3GS (White)
    i have managed to implement a continuos loop of a sample which plays in the background of my app. I did it by using a sample application called iDrum on appsamuck.com.

    i have also managed to stop the continuos loop by pressing a UIBarButtonItem

    however xCode comes up with a warning saying that my implementation of the function is not complete.

    the function is
    Code:
    - (void)stopBackgroundMusic{
    	SoundEngine_StopBackgroundMusic([I]Boolean inStopAtEnd[/I]);
    }
    but i didnt know what to do with the Boolean inStopAtEnd inside the brackets so i just left it empty, thats why xcode is warning me.

    can anyone tell Boolean inStopAtEnd means and what i am meant to replace it with.

    Thanks,
    JackMcLean
  2. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    It means YOU should put a BOOL there, so... YES or NO.
    "inStopAtEnd" means that if you put YES it will stop the music at the end. Say you listen to a song that will get repeated over and over again...
    Put NO so it stops immediately, put YES so it stops after the song is played.
  3. DotSlashSlash

    DotSlashSlash Active Member

    Joined:
    Feb 29, 2008
    Messages:
    1,134
    Likes Received:
    0
    Device:
    iPhone 3GS (White)

    Please Register or Log in to view images

    thanks you soo much

    Please Register or Log in to view images

    i was i understand now but i just didnt know what boolean meant, i know what bool means

    Please Register or Log in to view images

    would add rep.. but no rep system

    Please Register or Log in to view images


    Thanks again!
    ------------------double post merged------------------
    works great! would it be really hard to make the same button or another button play it again? after its has been stoped
  4. Teddyx

    Teddyx New Member

    Joined:
    Mar 18, 2008
    Messages:
    73
    Likes Received:
    0
    Device:
    iPhone 3GS (White)
    Doesn't boolean mean true or false? .. when i was learning about coding thats what i remember..and i can't remember using different..
  5. DotSlashSlash

    DotSlashSlash Active Member

    Joined:
    Feb 29, 2008
    Messages:
    1,134
    Likes Received:
    0
    Device:
    iPhone 3GS (White)
    http://en.wikipedia.org/wiki/Boolean_datatype
    apparently it does ^^^^^ but on the iphone SDK, a BOOL response is always YES or NO


    ________________________

    UPDATE
    ok i couldnt figure out a way replaying the repeating background sound after i stoped it so i just declared another sound file on the play button instead which works fine.

    but if anyone knows how to get one button to play and pause it would be awesome!
  6. godogshomie

    godogshomie New Member

    Joined:
    Nov 19, 2007
    Messages:
    558
    Likes Received:
    3
    Actually a BOOL is YES, NO, TRUE, FALSE, 1, and 0
  7. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    I don't know your code, but you should be able to check if the music is playing:
    Code:
    - (void)toggleMusicButtonClicked {
    if (backgroundMusicIsPlaying) {
    	SoundEngine_StopBackgroundMusic(NO);
    	backgroundMusicIsPlaying = NO;
    } else
    	// I don't know what method you have there.. but it should be like that I think:
    	SoundEngine_StartBackgroundMusic;
    (Notice: there is no need for {} after else because it's just one line that should be called in the else statement.)
    You'd set the BOOL to YES in the method that starts the music so you know if it's played atm. When the user presses the button you check if it's YES or NO so you can stop or start it.
    Make sure to declare the BOOL in your .h file and make it a property:
    Code:
    @interface WhatEver : DontKnow {
    	BOOL backgroundMusicIsPlaying;
    }
    
    @property (nonatomic, assign) BOOL backgroundMusicIsPlaying;
    
    @end
    
    And synthesize it in your .m file:
    Code:
    @implementation WhatEver
    
    @synthesize backgroundMusicIsPlaying;
    
    // Your Methods
    
    @end
    
  8. DotSlashSlash

    DotSlashSlash Active Member

    Joined:
    Feb 29, 2008
    Messages:
    1,134
    Likes Received:
    0
    Device:
    iPhone 3GS (White)
    thanks i will try that, i havent been that sure with if's and else's but it will try you code thanks

    Please Register or Log in to view images


    ------------------double post merged------------------
    the backgroundMusicIsPlaying function isnt working, i dunno if i have implemented it right, i got this in my viewController.h
    Code:
    @interface CountdownViewController : UIViewController {
    
    
    YES backgroundMusicIsPlaying;
    }
    
    @property (nonatomic, assign) YES backgroundMusicIsPlaying;
    
    @end
    
    and other stuff aswell

    and then in my viewController.m --
    Code:
    
    @synthesize backgroundMusicIsPlaying;
    
    - (void)toggleBackgroundMusic{
    	if (backgroundMusicIsPlaying) {
    		SoundEngine_StopBackgroundMusic(NO);
    		backgroundMusicIsPlaying = NO;
    	} else 
    		SoundEngine_StartBackgroundMusic(); }
    
    
    
    and other aswell but it keeps saying that the backgroundMusicIsPlaying is undeclared and.. it says there is an syntax error before '(' in the header file so i think that is related to the backgroundMusicIsPlaying also

    :/
  9. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    You have to pass a type there, in this case "BOOL" instead of "YES"!
  10. DotSlashSlash

    DotSlashSlash Active Member

    Joined:
    Feb 29, 2008
    Messages:
    1,134
    Likes Received:
    0
    Device:
    iPhone 3GS (White)
    what in the header file? so it would be like this
    Code:
    @interface CountdownViewController : UIViewController {
    
    
    [B]BOOL[/B] backgroundMusicIsPlaying;
    }
    
    @property (nonatomic, assign) YES backgroundMusicIsPlaying;
    
    @end 

Share This Page