0

I'm playing audio using AVPlayer but when it's playing there is no any information about it in bottom ios panel

So how can I add information about my audio here and synchronize system volume level with my UISlider in app which changed volume? Also it's very important to make play and pause buttons on locked screen but I don't know how to do this. I don't know obj-c too that's why some examples on stack is unuseable for me.

SwiftStudier
  • 2,272
  • 5
  • 21
  • 43
  • I think you need to enable background playing of audio in your application for it to work, see this [answer](http://stackoverflow.com/questions/30280519/how-to-play-audio-in-background-swift) – Scriptable Oct 11 '15 at 10:59
  • @Scriptable I did. It plays when I'm leaving app or lock screen – SwiftStudier Oct 11 '15 at 11:00
  • have you got this code also? `[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];`. It looks like you need to use the [MPNowPlayingInfoCenter Class](https://developer.apple.com/library/prerelease/ios/documentation/MediaPlayer/Reference/MPNowPlayingInfoCenter_Class/index.html) – Scriptable Oct 11 '15 at 11:02

1 Answers1

0

Possible Duplicate, Check this answer.

In case the link breaks, it seems you need to enable remote control events with:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 

This should enable the play/pause buttons to send controls to your application. You'll need to set the now playing information manually...

// Swift code, will need converting
var mpic = MPNowPlayingInfoCenter.defaultCenter()
mpic.nowPlayingInfo = [
    MPMediaItemPropertyTitle:"This Is a Test",
    MPMediaItemPropertyArtist:"Matt Neuburg"
]

You will also need to act on the control events received:

- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent {

    if (receivedEvent.type == UIEventTypeRemoteControl) {

        switch (receivedEvent.subtype) {

            case UIEventSubtypeRemoteControlTogglePlayPause:
                [self playOrStop: nil];
                break;

            case UIEventSubtypeRemoteControlPreviousTrack:
                [self previousTrack: nil];
                break;

            case UIEventSubtypeRemoteControlNextTrack:
                [self nextTrack: nil];
                break;

            default:
                break;
        }
    }
}
Community
  • 1
  • 1
Scriptable
  • 19,402
  • 5
  • 56
  • 72
  • This doest answer OP question, you are assuming that the OP knows the mp3 title and artist for every sound he will be playing. – Leo Dabus Oct 11 '15 at 11:15
  • I think this does answer the op's question, he does not HAVE to set the now playing information, or at least set it to the name. enabling the remoteControlEvents should enable the buttons to work on the home screen like he asked. he could set the title to anything "MyAppName - Audio" or whatever. And I did say possible duplicate... if it doesnt help then i'll gladly remove it. We wont know until he responds though. Oh and I never mentioned MP3 files at all? – Scriptable Oct 11 '15 at 11:17
  • That's it, thank you very much. But now how can I get value of volume-slider from bottom-panel and set the same value to my uISlide in my app? How to synchronize them? – SwiftStudier Oct 11 '15 at 12:08
  • https://developer.apple.com/library/prerelease/ios/documentation/MediaPlayer/Reference/MPVolumeView_Class/index.html – Leo Dabus Oct 11 '15 at 13:02
  • 1
    http://stackoverflow.com/a/31540153/2303865 – Leo Dabus Oct 11 '15 at 13:03