ios - AVAudioPlayer initWithURL not working to stream radio -
i'm trying stream radio in app.
i'm using avaudioplayer, have error don't understand :
nsstring *urlstring = @"http://broadcast.infomaniak.net/radionova-high.mp3"; nsurl *myurl = [nsurl urlwithstring:urlstring]; nserror *error; self.audioplayer = [[avaudioplayer alloc] initwithcontentsofurl:myurl error:&error]; if (self.audioplayer == nil){ nslog(@"error loading clip: %@", [error localizeddescription]); } else { self.audioplayer.delegate = self; self.audioplayer.volume = 0.5; [self.audioplayer play]; }
and have following error :
error loading clip: operation couldn’t completed. (osstatus error -43.)
does see what's wrong ?
edit :
this apple docs say:
the avaudioplayer class not provide support streaming audio based on http url's. url used initwithcontentsofurl: must file url (file://). is, local path.
now ? :(
download file document directoty play file
nsstring *urlstring = @"http://broadcast.infomaniak.net/radionova-high.mp3"; nsurl *myurl = [nsurl urlwithstring:urlstring]; nsdata *audiodata = [nsdata datawithcontentsofurl:myurl]; nsstring *docdirpath = [nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) objectatindex:0]; nsstring *filepath = [nsstring stringwithformat:@"%@/%@.mp3", docdirpath , filename]; [audiodata writetofile:filepath atomically:yes]; nserror *error; nsurl *fileurl = [nsurl fileurlwithpath:filepath]; self.audioplayer = [[avaudioplayer alloc] initwithcontentsofurl:fileurl error:&error]; if (self.audioplayer == nil) { nslog(@"audioplayer did not load properly: %@", [error description]); } else { self.audioplayer.delegate = self; self.audioplayer.volume = 0.5; [self.audioplayer play]; }
Comments
Post a Comment