Music playback
nsstring *path = [[ NSBundle<] Span style= "Color:rgb (255,255,255)" > mainbundle] Pathforresource: @ " Span style= "font-family:"heiti SC light"; Color:rgb (255,70,71) "> premeditated " oftype: @" MP3 " ";
if (path) {
nsurl *url = [nsurlfileurlwithpath:p Ath];
player= [[avaudioplayeralloc]initwithcontentsofurl: URL Error:nil];
[playersetdelegate:Self];
player. Volume =1;
player. Pan =1;
player. numberofloops =-1;
if ([playerpreparetoplay]) {
NSLog (@ "preparetoplay:%@", Path);
[playerplay];
} Else {
NSLog(@ "no preparetoplay");
}
//[player release];
}
Be sure to note the player's reference, assuming that a temporary variable is requested directly inside the function. Then the player will be released when the function is run and the release will be freed, assuming it needs to be used inside the function. then please sleep. Just this will block the main thread's operation.
Video player
Nsurl * Movieurl = [nsurlurlwithstring:@ "http://v.youku.com/player/ Getrealm3u8/vid/xnduwnjc4mza4/type/video.m3u8 "];
mpmovieplayerviewcontroller *player = [[mpmovieplayerviewcontrolleralloc] Initwithcontenturl: Movieurl];
[self presentmovieplayerviewcontrolleranimated:p layer];
IOS calls music playback and video player