0
votes

I am using AVPlayer to play music from an external url.

I've accomplished to play and pause the audio.

But I can't have a track duration method.

The variable duration gives me the track duration in seconds.

I wan't to make a slider / label that shows the music current length.

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    let playTrackID = tracks[indexPath.row].trackID

    let urlString = url

    let url = NSURL(string: urlString)!

    avPlayer = AVPlayer(URL:url)

    let duration = self.avPlayer.currentItem?.asset.duration

    avPlayer.play()

}

Any idea?

Thanks

1

1 Answers

0
votes

Create a URL connection object with a delegate object that conforms to the NSURLConnectionDelegate and NSURLConnectionDataDelegate protocols. The NSURLConnectionDataDelegate protocol provides methods that the NSURLConnection class calls with progress information during an upload, and with fragments of the response data during a download.