Ok this is going to be long. Loosely copied from the link you provided. There is an example project in swift as well, but I can’t really read swift so didn’t look at it. Maybe it is useful to someone.
This code is UNTESTED but is probably pretty close to what you need to do
Open event:
Sub Open()
SetupControls()
SetupNowPlaying()
End Sub
Add the functions:
[code]Sub SetupControls()
// setup the AVAudioPlayer here in “self.player”
declare function sharedCommandCenter lib “MediaPlayer” selector “sharedCommandCenter” (clsRef as Ptr) as ptr
declare Function addTarget lib “MediaPlayer” selector “addTargetWithHandler:” (obj_id as ptr, blk as ptr) as ptr
declare sub setEnabled lib “MediaPlayer” selector “enabled” (obj_id as ptr, yesNo as Boolean)
// repeat this for all commands (I believe)
// ie, play, pause, stop, togglePlay/Pause
// nextTrack, previousTrack, etc
// NOTE: you MUST call “setEnabled(XYZcmd, False)” for any of the commands you do not support or your app will not work
// see https://developer.apple.com/documentation/mediaplayer/mpremotecommandcenter?language=objc
declare function playCommand lib “MediaPlayer” selector “playCommand” (obj_id as ptr) as ptr
dim sharedCenter as Ptr = sharedCommandCenter(NSClassFromString(“MPRemoteCommandCenter”))
dim playCmd as Ptr = playCommand(sharedCenter)
// if you want this command (item of the player when displayed on the lock screen) to be disabled do the following
//setEnabled(playCmd, False)
// if you want to handle the command, add a function for it, and add the following
dim blk as new iOSBlock(AddressOf PlayCommandHandler)
call addTarget(playCmd, blk.Handle)
// repeat for all commands you care about…
End Sub
[/code]
[code]Sub SetupNowPlaying()
declare function defaultCenter lib “MediaPlayer” selector “defaultCenter” (clsRef as ptr) as ptr
declare sub setNowPlayingInfo Lib “MediaPlayer” selector “setNowPlayingInfo:” (obj_id as ptr, info as ptr)
Declare function numberWithInt lib FoundationLib selector “numberWithInt:” (clsRef as ptr, int as Integer) as ptr
dim nowPlayingInfo as new Foundation.NSMutableDictionary
nowPlayingInfo.Value(new NSString(“title”)) = new NSString(“My song title”)
// set duration, in seconds
nowPlayingInfo.Value(new NSString(“playbackDuration”)) = numberWithInt(NSClassFromString(“NSNumber”), 10)
// there are other properties that can be set… some easier and some more difficult. if you need them I can try and show how for some
// see https://developer.apple.com/documentation/mediaplayer/mpnowplayinginfocenter?language=objc#1674387
dim defCtr as ptr = defaultCenter(NSClassFromString(“MPNowPlayingInfoCenter”))
setNowPlayingInfo(defCtr, nowPlayingInfo)
End Sub
[/code]
Now add a command handler callback for every command you intend to support (you might need to have like 10 of these depending on the number of events you support)
[code]Function PlayCommandHandler(evt as ptr) As Integer
// possible return values from this function:
const success = 0
const failed = 200
const NoActionableNowPlayingItem = 110
const NoSuchContent = 100
if self.player.rate == 0
self.player.play()
return success
end if
return failed
#Pragma unused evt
End Function
[/code]