ios - How to change NSIndexPath in another UIViewController in swift -


i nsindexpath array uitableviewcontroller , nsindexpath of specific file. mp3 files document folder in nsindexpath array , specific file selected row uitableviewcell in nsindexpath file.

i want switch mp3 files need change nsindexpath in uiviewcontroller plays music. or there different methods switching mp3 files document folder?

the uitableviewcontroller code

    override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {     var playervc = (segue.destinationviewcontroller as! uinavigationcontroller).topviewcontroller as! playmusicviewcontroller     var indexpath = tableview.indexpathforselectedrow()     var nameofobjectforpass = listofmp3files![indexpath!.row] // default it's name ,     var filemanager = nsfilemanager.defaultmanager()      var waytofile = filemanager.urlsfordirectory(nssearchpathdirectory.documentdirectory, indomains: nssearchpathdomainmask.userdomainmask)     var passmusicfileurl: nsurl? // pass mp3      if let documentpath: nsurl = waytofile.first as? nsurl {         let musicfile = documentpath.urlbyappendingpathcomponent(nameofobjectforpass)         println(musicfile)         passmusicfileurl = musicfile     }      var currenttrackindex = tableview.indexpathforselectedrow()!      var allindextable = tableview.indexpathsforvisiblerows()! as! [nsindexpath]      if segue.identifier == "listenmusic" {         playervc.namemusicfile = nameofobjectforpass // name         playervc.mp3url = passmusicfileurl          // test           playervc.currentindex = currenttrackindex          playervc.allindex = allindextable     } } 

the uiviewcontroller code

var currentindex: nsindexpath! var allindex = [anyobject]() as! [nsindexpath]  func playnextsound() {     println("index \(currentindex)")      println("all object \(allindex)")     var indextfound = find(allindex, currentindex)             println("index found \(indextfound)")  } 

the code plays music

 func playmusic() {     avaudiosession.sharedinstance().setcategory(avaudiosessioncategoryplayback, error: nil) // == true     avaudiosession.sharedinstance().setactive(true, error: nil)     var error: nserror?     audioplayer = avaudioplayer(contentsofurl: mp3url, error: &error)    // audioplayer.preparetoplay()     if currentpause == nil {     } else {         audioplayer.currenttime = currentpause     }     //     audioplayer.volume = 0.5     audioplayer.play() } 

i following results in console

index {length = 2, path = 0 - 0} current object

it object document folder object [ {length = 2, path = 0 - 0}, {length = 2, path = 0 - 1}]

var newurl: nsurl! @ibaction func nexttrack(sender: uibutton) {     println("touched next")     var nowrow: int = self.currentrow     var maxcount = self.arrayofmp3.count-1 // -1     if nowrow < maxcount {         nowrow = self.currentrow++         println("plus")     } else if nowrow == arrayofmp3.endindex {         nowrow = maxcount         println("equals")     }     // play/pause button setting      currentpause = nil     //println("current pause\(currentpause)")     next = false     //      println("current row \(currentrow)")     println("end index \(arrayofmp3.endindex)")      var nexttrack = arrayofmp3![nowrow]      var nextdirectory = filemanager.urlsfordirectory(nssearchpathdirectory.documentdirectory, indomains: nssearchpathdomainmask.userdomainmask)      if var nexturl: nsurl = nextdirectory.first as? nsurl {         newurl = nexturl.urlbyappendingpathcomponent(nexttrack)     }      var nameartist: string!     var namesong: string!     var imagestring: nsdata!      var itemplayer = avplayeritem(url: newurl)      var listmetadata = itemplayer.asset.commonmetadata as! [avmetadataitem]     item in listmetadata {         if item.commonkey == "title" {             namesong = item.stringvalue         }         if item.commonkey == "artist" {             nameartist = item.stringvalue         }         if item.commonkey == "album" {             item.stringvalue         }         if item.commonkey == "artwork" {             imagestring = item.datavalue         }     }      namelabel?.text = "\(nameartist) \(namesong)"     if imagestring != nil {         imageview?.image = uiimage(data: imagestring)     } else {         imageview?.image = nil     }     tapbuttonplay = false     playmusic() } 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -