iOS SDK : playing music on the background and switching views

后端 未结 5 1468
北荒
北荒 2020-12-03 16:09

I am trying to play music in my application. The music works fine but after switching viewControllers and returning to the main menu, my music plays again! It means several

5条回答
  •  醉话见心
    2020-12-03 16:57

    Its seems you are developing game (from your function name After viewLoad (ScoreView). ;) )

    Well, According to me, AvAudioplayer is not Good Option if you want to implement with Game.

    Use cocosdenshion, Download the latest cocos2d folder, find the these 9 files, put it in your resource folder,

    And You are done.. !!!

    #import "SimpleAudioEngine.h" // wherever you want to call in head part of the file.
    

    Step1 call short file.!

    [[SimpleAudioEngine sharedEngine] playEffect:@"blast.mp3"];
    

    step2 call background loop.

    [[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"background.mp3" loop:YES];
    

    NOTE: There are list of available function http://www.cocos2d-iphone.org/api-ref/0.99.5/interface_simple_audio_engine.html , Its very easy and simple !

    Whole implementation will take, 20 minutes max !

提交回复
热议问题