Avaudioplayer: Easy to use, but only local audio files can be played, no streaming media files
Note: When loading the path of the local audio file, you cannot use nsurl *url = [Nsurl Urlwithstring:musicpath]; This sentence is to convert the network path to a URL; load local Nsurl *url = [Nsurl Fileurlwithpath:musicpath];
For example :
_player is a Avaudioplayer object that plays audio and video files, creates the player to be placed in the global, otherwise, cannot play nsstring *musicpath = [[NSBundle Mainbundle] pathforresource:@ "Music" oftype:@ "MP3"; Convert network link//Nsurl *url = [Nsurl Urlwithstring:musicpath]; Local path Nsurl *url = [Nsurl Fileurlwithpath:musicpath]; _player = [[Avaudioplayer alloc] Initwithcontentsofurl:url Error:nil]; _player.delegate = self; [_player Preparetoplay];
Avplayer: Can play local audio or stream media
_player1 is a Avplayer object that can play streaming audio nsstring *str = @ "http://www.soge8.com/1424215157/ E4eaa401acb097ad2745efe7f8213352.mp3 "; _player1 = [[Avplayer alloc] Initwithurl:[nsurl Urlwithstring:str]];
Register your system's voice:
Get file path NSString *filepath = [[NSBundle Mainbundle] pathforresource:@ "44th Street MEDIUM.CAF" Oftype:nil]; Nsurl *url = [Nsurl Fileurlwithpath:filepath]; UInt32 soundid = 0; Register the System Sound Audioservicescreatesystemsoundid ((__bridge cfurlref) (URL), &soundid); Playback system Sound Audioservicesplaysystemsound (Soundid); Mobile phone shake//can use Audioservicesplaysystemsound (ksystemsoundid_vibrate);
Audio and video processing in iOS