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/