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 -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -