ios - AVPlayerItem from URL not playing -


i'm trying play mp3 data file downloaded alamofire. song fine, can play avaudioplayer(data: data). how should play same data file avplayer? not find how create playeritem data or avasset data. also, i've url song path, url not work avplayer somehow. music not playing.

func startsong(withindex: int) {     if let item = getitem(atindex: withindex) {         {             try avaudiosession.sharedinstance().setcategory(avaudiosessioncategoryplayback)             print("avaudiosession category playback ok")             {                 try avaudiosession.sharedinstance().setactive(true)                 print("avaudiosession active")             } catch let error nserror {                 print(error.localizeddescription)             }             let playeritem = item             self.player = avplayer(playeritem: playeritem)         } catch let error nserror {             print(error.localizeddescription)         }     } }  func getitem(atindex: int) -> avplayeritem? {      var item: avplayeritem      var url: url      let song = playlist.getsong(index: atindex)      if playlistsservice.sharedservice.isfiledownloaded(inpath: songpath.offline(id: (song?.getid())!).path()) {         url = url(fileurlwithpath: songpath.offline(id: (song?.getid())!).path())     } else if playlistsservice.sharedservice.isfiledownloaded(inpath: songpath.temp(id: (song?.getid())!).path()) {         url = url(fileurlwithpath: songpath.temp(id: (song?.getid())!).path())     } else {         self.downloadsong(song: song!)         url = url(fileurlwithpath: songpath.temp(id: (song?.getid())!).path())     }      item = avplayeritem(url: url)      return item }  @ibaction func playpause(_ sender: uibutton) {     sender.isselected = !sender.isselected     if sender.isselected {         print("play")         self.player.play()     } else {         print("pause")         self.player.pause()     } } 

just found out avplayeritem cannot create object url points data file. need have url file extension ".mp3" instance. working when i've added extension path downloading , playback.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

Laravel mail error `Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [ #0]` -

c# SetCompatibleTextRenderingDefault must be called before the first -