play sequential audio files swift -
hi im trying play several audio files 1 after other.
here's code have play 1 audio file names "1". can play group of audio files sequentiall?
import uikit import avfoundation class viewcontroller: uiviewcontroller { var ding:avaudioplayer = avaudioplayer() override func viewdidload() { super.viewdidload() prepareaudios() ding.play() } func prepareaudios() { var path = nsbundle.mainbundle().pathforresource("1", oftype: "mp3") ding = avaudioplayer(contentsofurl: nsurl(fileurlwithpath: path!), error: nil) ding.preparetoplay() } }
you can use avqueueplayer play multiple audio sequentially.
class viewcontroller: uiviewcontroller { var playerqueue: avqueueplayer = { let url1 = nsbundle.mainbundle().urlforresource("uptown", withextension: "mp3")! let url2 = nsbundle.mainbundle().urlforresource("turnmeon", withextension: "mp3")! let item1 = avplayeritem(url: url1) let item2 = avplayeritem(url: url2) let queue = avqueueplayer(items: [item1, item2]) return queue }() override func viewdidload() { super.viewdidload() playerqueue.play() } }
Comments
Post a Comment