MPMusicPlayerController (XCode vs. Xojo)

Does anyone have declares/classes already worked out for MPMusicPlayerController? I have a small app I wrote for my wife that uses it to make cueing easier for when she teaches fitness classes at the rec center. Music app on the iPhone is horrible for being able to see the elapsed time of a song at any distance. The app broke recently and I thought I might try porting the app over to Xojo.

It’s turning out to be a bit more challenging than I thought. I think most of the declares and such I need are already available in iOSKit or iOSLib, but I’m having a little trouble with MPMusicPlayerController and the associated MPMediaItem classes. I don’t have a lot of time to work on this but I figured I’d spend a little bit here and there to get these classes working, but I definitely don’t want to reinvent the wheel. It will probably take me several months to get it working with spending just a hour here or there on it.

I did have a few hours to work on it this weekend and I only managed to get a handful of declares compiling in Xojo. Nothing is yet to the point where I can actually do anything with it. I gave up on getting it working for her Monday classes so I reworked the old XCode project and managed to get it usable even though it has weird warnings that I don’t understand. It will at least get the job done for now so she doesn’t have to squint at the tiny text in Music. That will buy me some time to either get the XCode project fixed or rebuilt, or get MPMusicPlayerController working in Xojo.

This experience has definitely convinced me that if Xojo can get more of the frameworks built in it will be much nicer to work with than XCode. Unfortunately right now it’s extremely limiting. If I don’t make more progress or get my head wrapped around the declares and frameworks better I may just try rebuilding it in Swift. There’s way too much to learn as a part time developer and it seems like it’s getting worse not better.

Give me an hour and I’ll see what progress I can make with this. Are there specific features of the class you know you need/don’t need so I can have a more focused approach?

This is a VERY rough first implementation:
https://www.dropbox.com/s/wvq8d8oxjlls527/MediaPlayer.xojo_binary_project?dl=0

It should work although the code is untested on a physical device and can’t be tested on the simulator because there is no music playback. To test it, upload the app to your phone then start playing a song on the phone and press the button. It should display a message box with the name of the song playing.

Let me know how it goes,
Jason

Wow, that’s great Jason. I already see a couple of things that I did wrong.

Basically what my app does is allow the user to pick a playlist, then play/pause, fast forward and rewind, skip tracks back and forward, and it displays the title, album/artist, and the elapsed and remaining time.

I think what you have done so far is a really good start, and seems to work fine on my phone.

It looks like you have much of what I need there. I don’t see play,pause,ff,rewind, and the notification functions for being alerted when the player state changes, but I will fill those in as I go and if I get stuck I’ll let you know.

If you don’t beat me to the finish line on this one, I’ll check back and send my changes somehow so you can add it to the github repo.

Thanks a bunch.

I have a few small additions I added to the class to be able to handle the few missing features I needed. Jason should I send you my copy of the class so you can add the changes in for future users?

It’s still incomplete, but at least it has enough functionality to make a working player app.

Sure, although I’m very busy so it is unlikely I’ll be able to make any large changes to iOSKit for a while.

No worries, In testing and cleaning up the last few ui glitches I’ve discovered that for some reason I can’t advance through the entire playlist. It seems like it has something to do with UInteger in the return of a declare, but I’ve switched it out to Integer, UInt32 and it’s been very frustrating trying to figure out why it won’t work.

I did get it to work once, but on subsequent compiles it has failed again.

I’ve also run into another oddity where adding a longpress gesture to a button has prevented the built in tap action from working. That also seemingly quit working for no reason. I didn’t change any code related to that part of the app after I got it working and it just quit.

So I’m trying to isolate things and figure out if it’s a bug or something related to my code, but so far it has me stumped. I think I’ve spent more time now trying to deal with bizarre oddities than actually writing app code. So close to having everything working too. I thought I was just two minor changes from done. Must have jinxed myself.