iOS Remote Audio / Objective C / Declares question

Declares code or at the very least an Objective C reference source like is used in the XOJO video about Declares, that actually has the info needed to create declares. Apple’s documentation has apparently gotten significantly less useful.

I found Jason King’s response to a post titled ’ remote audio help needed again’ but I wasn’t able to get it working. I thought maybe I need to use an older XOJO version to get it to work.

Are there any MpRemoteCommandCenter and MPNowPlayingInfoCenter plug-ins ?

From here down is the Jason King response mentioned above that I found:

[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 MPRemoteCommandCenter | Apple Developer Documentation
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 MPNowPlayingInfoCenter | Apple Developer Documentation

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]