1

I have audio app. For listening audio i use AVFoundationFramework and make it in background with info by MPNowPlayingInfoCenter. If user making segue to other screen the audio are playing. I want show him info about playing audio on this new screen. The most problem is getting current time of playing in background audio. How can i get it?

P.S.: Length of audio primarily equals to one hour.

P.P.S.: I will be pleased to get answer in any language (obj-c/Swift)

EDIT: in iOS remote center shows true info, i just need get it in code... screenshot: http://postimg.org/image/9lv60eb1n/

DeveloBär
  • 673
  • 8
  • 20
mike
  • 13
  • 6

2 Answers2

0

You can get the current time of the audio via using

MPNowPlayingInfoPropertyElapsedPlaybackTime

e.g. something like

if let nowPlayingInfoDict = MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo
{
    let elapsedTimeString = nowPlayingInfoDict["MPNowPlayingInfoPropertyElapsedPlaybackTime"]
}

where the value is a NSNumber representing the number of seconds played in the item so far.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • do you get a dictionary (and if so, what are the various keys & values you see in there)? – Michael Dautermann Feb 20 '16 at 12:39
  • i got a dictionary which include all info what i write in MPNowPlayingInfoCenter: title, name etc.. but ElapsedPlaybackTime is NULL – mike Feb 20 '16 at 12:45
  • Oh, is the thing you are playing a local file or some streaming thing from a remote site (in which case there is no fixed duration)? – Michael Dautermann Feb 20 '16 at 12:54
  • online and offline. in both cases i know duration and current time for AVPlayer, but for background audio don't working in both cases – mike Feb 20 '16 at 13:05
  • in iOS remote center shows true info, i just need get it in code... screenshot: http://postimg.org/image/9lv60eb1n/ – mike Feb 20 '16 at 13:19
0

I still don't know how make it (take info from remote center), but i solved it by singleton for audio player.

mike
  • 13
  • 6