User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13

Thread: Small Guide: Don't stop sound from other sources and mute own game sound

  1. #1
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export Module

    Join Date
    Apr 2010
    Location
    Germany
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Small Guide: Don't stop sound from other sources and mute own game sound

    Hey there,

    I have no idea in how to code in xCode and I wanted my game to stop its own music and sound, when it's started while music/sound from an other app is playing (like podcasts or... music :P). Since the solution from DavidN (http://community.clickteam.com/threads/69128-iPod-music-during-game-Solved!-%28I-think%29) is quite old and Fusion made games will just stop other music by default - I thought I share this with you.

    So this is what I came up with while searching the web:

    Change "AVAudioSessionsCategorySoloAmbient" to "AVAudioSessionsCategoryAmbient" in CALPlayer.m and CSoundPlayer.m (both are in Classes/Application/Sound). This will prevent your game from stopping the other music source.
    Now put this code into the "-(id)initWithApp: (CRunApp*)app {...}" section right before "return self;"

    Code:
    UInt32 otherAudioIsPlaying;
    UInt32 sizeOtherAudio = sizeof(otherAudioIsPlaying);
    AudioSessionGetProperty(kAudioSessionProperty_OtherAudioIsPlaying, &sizeOtherAudio, &otherAudioIsPlaying);
    
    if(otherAudioIsPlaying){
        mainVolume=0;
    }
    This will set the Main Volume to 0 when other music is playing. If you're working with INI-Settings to enable/disable music or sound in your game, just check if your Main Volume got set to 0 and change your INI value (didn't test this though).
    Make a backup please, if you're going to test this. It works fine for me, but I have no idea if it will break anything in your game

  2. #2
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export Module
    paobrasil's Avatar
    Join Date
    Apr 2012
    Location
    Rio de Janeiro, Brazil
    Posts
    1,146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    amazing guide, thank you very much!

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUnicode Add-onInstall Creator

    Join Date
    Jul 2006
    Posts
    1,018
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool, thank you.

  4. #4
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    DavidN's Avatar
    Join Date
    Jun 2006
    Location
    Boston, MA, USA
    Posts
    4,044
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent, thanks for updating that - and for the way to detect it from within the application, as well!

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator ProPatch Maker

    Join Date
    Jun 2006
    Location
    Norway
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this solution still possible with the latest version of F2.5/xcode 6?
    I searched for "AVAudioSessionsCategorySoloAmbient" in my xcode project, it didn't find anything.

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export Module

    Join Date
    Apr 2010
    Location
    Germany
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh god! My fault. It should've been "AVAudioSession..." not "Sessions". Arghs!

  7. #7
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export Module
    Outcast's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    3,191
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Very nice!

    I wonder instead of using

    if(otherAudioIsPlaying){
    mainVolume=0;
    }

    Could you put some change to a global value? I am not sure how it works in xcode, but I dont use mainVolume when handling volume in my apps. It would be easier if i could just check against a regular value.

    Btw, is there some similar method for Android?

  8. #8
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export Module
    Outcast's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    3,191
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    I did this once but now I cant remember where I found this:

    Now put this code into the "-(id)initWithApp: (CRunApp*)app {...}" section right before "return self;"

    Where is this exactly, in what section?

  9. #9
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export Module
    Outcast's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    3,191
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Ok I found it.

    But another thing, I treid to compare two general values and see if the main volume is equal or lower then 0 at the start of the app and if so increase a value by 1 but it never increases. The main volume is still 100 but the implementation still made it so I can play other music in the background. It just plays everhthing at the same time.

  10. #10
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export Module

    Join Date
    Apr 2010
    Location
    Germany
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't test the "MainVolume = 0" xcode stuff, so I didn't know if it'd work. It was just a theory.

    We just added two checkboxes in our options menu to mute sound and music. If anyone wants to listen to a podcast or music from his phone, he just has to uncheck the music option.

Page 1 of 2 1 2 LastLast

Similar Threads

  1. A small Android sound example
    By tweettopix in forum Android Export Module 2.5
    Replies: 3
    Last Post: 18th August 2014, 08:18 AM
  2. [Bug/Feature] Should apps play sound when phone on mute?
    By AdamDobay in forum Android Export Module Version 2.0
    Replies: 2
    Last Post: 22nd December 2011, 12:25 AM
  3. The sound will not stop
    By Rabagast in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 16th November 2009, 05:27 AM
  4. A feature to stop sound/music?
    By Dines in forum Vitalize
    Replies: 22
    Last Post: 22nd December 2007, 07:28 AM
  5. Sound on/off?! Mute?
    By Blizna in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 7th January 2007, 02:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •