[Iphone-cocos2d] share an objective-C callable game playing music (2)

Source: Internet
Author: User
Next, we will encapsulate the functions at the bottom, so that they can be used more conveniently. Code Static Gbmusictrack * Track;
Static Nsmutabledictionary * Trackfiles;
Static Bool enabled _ = True;
Static Bool musicvolume _ = 1.0f ;

// // Add the audio file to the dictionary by name // + ( Void ) Addmusictrack :( nsstring * ) Filename name :( nsstring * ) Name {
If (Trackfiles = Nil ){
Trackfiles = [[Nsmutabledictionary alloc] init];
}
[Trackfiles setobject: Filename forkey: Name];
} //// Check whether the dictionary is empty and whether there are any audio files. //
+ (Bool) hasmusictrack :( nsstring * ) Name {
Id OBJ = [Trackfiles objectforkey: Name];
If (OBJ = Nil) Return False;
Else
Return True;
}
// // Encapsulate the method mentioned above. The parameter is the name of the playback and whether to play the video repeatedly. //
+ ( Void ) Playmusictrack :( nsstring * ) Name withrepeat :( bool) B {
# Ifndef debug_no_sound
If ( ! Enabled _) Return ;
If (Trackfiles = Nil) Return ;

If (Track ! = Nil ){
@ Try {
[Self stopcurrenttrack];
}
@ Catch (nsexception * Ex ){
Nslog ([ex description]);
}
}
// // This function initwithpath is mentioned above. Initialization Method. //
Track = [[Gbmusictrack alloc] initwithpath: [nsbundle mainbundle]
Pathforresource: [trackfiles objectforkey: Name]
Oftype: @" MP3 " ];
[Track setrepeat: B];
[Track setvolume: musicvolume _]; // Play music //
[Track play];
# Endif
}

 

Add a link for anti-theft:

Author: alexliu (Alex DOTNET learning)
Source: http://alexliu.cnblogs.com/

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.