I can't read the message below, I'll explain.
-(void) Audioplayerdecodeerrordidoccur: (Avaudioplayer *) Player ERROR: (NSERROR *) error
{
[Self ordertoplaybackgroundmusic];
}
-(void) audioplayerdidfinishplaying: (Avaudioplayer *) player successfully: (BOOL) flag
{
[Self ordertoplaybackgroundmusic];
}
-(void) Ordertoplaybackgroundmusic
{
[Singletontool defaultmemory].musicindex++;
if ([Singletontool defaultmemory].musicindex = [[Singletontool defaultmemory].musicarray Count])
{
[Singletontool defaultmemory].musicindex = 0;
}
NSString * Musicname = [[Singletontool defaultmemory].musicarray Objectatindex:[singletontool defaultMemory]. Musicindex];
NSString * Musicfilepath = [[NSBundle mainbundle] pathforresource:musicname oftype:@ "MP3"]; Create a music file path
Nsurl * musicurl= [[Nsurl alloc] initfileurlwithpath:musicfilepath];
Avaudioplayer * Theplayer = [[Avaudioplayer alloc] Initwithcontentsofurl:musicurl Error:nil];
Theplayer.delegate = self;
[Theplayer play];
[Theplayer setvolume:1]; Set Volume size
Theplayer.numberofloops = 1;//Set Music playback number-1 to always loop
[Musicurl release];
[Singletontool defaultmemory].theplayer = Theplayer;
[[Singletontool Defaultmemory].playerarray removeallobjects];
[[Singletontool Defaultmemory].playerarray Addobject:theplayer];
}
-(void) Playbackgroundsound
{
[Singletontool Defaultmemory].musicarray = [[Nsmutablearray alloc] initwithcapacity:0];
[[Singletontool defaultmemory].musicarray addobject:@ "Hatsune ミク-world is Mine"];
[[Singletontool defaultmemory].musicarray addobject:@ "Avril Lavigne-girlfrieng"];
[[Singletontool Defaultmemory].musicarray addobject:@ "Bang-qi あゆみ-evolution"];
[[Singletontool defaultmemory].musicarray addobject:@ "Plant vs. Zombie Customs Song"];
[[Singletontool Defaultmemory].musicarray addobject:@ "initial tone ミク-furnace heart melt"];
[[Singletontool defaultmemory].musicarray addobject:@ "Du Yan-Millennium," the theme song of the Chinese Paladin "];
[[Singletontool Defaultmemory].musicarray addobject:@ "first sound ミク-deep-sea maiden"];
int k = Arc4random ()%3;
Switch (k)
{
Case 0:
[Singletontool defaultmemory].musicindex = 0;
Break
Case 1:
[Singletontool defaultmemory].musicindex = 2;
Break
Case 2:
[Singletontool defaultmemory].musicindex = 3;
Break
Default
[Singletontool defaultmemory].musicindex = 3;
Break
}
Avaudiosession *audiosession = [Avaudiosession sharedinstance];
Nserror *err = nil;
[Audiosession Setcategory:avaudiosessioncategoryplayandrecord error:&err];
if (ERR)
{
NSLog (@ "audiosession:%@%d%@", [err domain], [ERR code], [[Err UserInfo] description]);
}
[Audiosession Setactive:yes error:&err];
Err = nil;
if (ERR)
{
NSLog (@ "audiosession:%@%d%@", [err domain], [ERR code], [[Err UserInfo] description]);
}
Disable automatic lock screen when program is running
[[UIApplication sharedapplication] setidletimerdisabled:yes];
NSString * Musicfilepath = [[NSBundle mainbundle] Pathforresource:[[singletontool Defaultmemory].musicarray Objectatindex:[singletontool Defaultmemory].musicindex] oftype:@ "MP3"]; Create a music file path
Nsurl * musicurl= [[Nsurl alloc] initfileurlwithpath:musicfilepath];
Avaudioplayer * Theplayer = [[Avaudioplayer alloc] Initwithcontentsofurl:musicurl Error:nil];
Theplayer.delegate = self;
[Theplayer play];
[Theplayer setvolume:1]; Set Volume size
Theplayer.numberofloops = 1;//Set Music playback number-1 to always loop
[Musicurl release];
[[Singletontool Defaultmemory].playerarray Addobject:theplayer];
[Singletontool defaultmemory].theplayer = Theplayer;
Half the song out of the background stop after
/*mpmusicplayercontroller *musicplayer = [Mpmusicplayercontroller Ipodmusicplayer];
Mpmusicplaybackstate playbackstate = musicplayer.playbackstate;
if (playbackstate = = Mpmusicplaybackstatestopped | | playbackstate = = mpmusicplaybackstatepaused) {
[Musicplayer play];
else if (playbackstate = = mpmusicplaybackstateplaying) {
[Musicplayer pause];
}*/
}