Playback events?

Hi all - the site I’m trying to write a plugin for does a few odd things.



First, for music licensing purposes they request that we make a JSON or XML call 30 seconds after a track starts playing. Is there any way to do this? I’m thinking I can create a new thread with a 30 second delay when the song starts playing, I’m just not sure if there’s a way to be notified when the song starts playing? I know I can create a callback function for the URL of the song - but will that get called when the song starts playing, or before that when the menu item gets created? i.e. dir.append(TrackItem(callback(Playback),title=title)), and then my Playback function would create a new thread that would delay 30 seconds before calling another function that would perform their requested API call, and after the thread is created return the song’s URL.



Also, is there any way to be notified / call a function when the end of a song is reached? The way their API works, they initially tell you the URL of the first song but you have to make additional API calls to get the URL of the next song. It seems the appropriate time to do this (at least in the spirit of the site’s user agreement) is to only get the URL for the next song once the current song has completed.

There isn’t currently any sort of playback notification hooks implemented. I’ve heard that it’s on the roadmap but there’s no indication as to when it will be implemented. I think your concept of a callback to create a separate thread with a 30-second delay seems like a reasonable workaround. By the same token, there is no hook/notification for when an item is finished playing aside from control returning from the player to the plugin code.



Not exactly the sort of answer you were looking for I imagine. Perhaps with a little more info, I might be able to think of some better advice. What format are the TrackObjects? Do you have direct access to MP3s (or similar) or are you planning on using a Site Config to lock on to a Flash audio player? Do you know how many tracks are in the playlist before you start? Do you know anything about the next tracks before you make the obligatory API call? Like an id or some other unique string that can be passed to a callback to make the necessary API call?


Thanks for your reply. The site's API ultimately gives URL's directly to the songs (.m4a files). There are two problems.

The first is that they want you to hit a specific URL 30 seconds after the song starts playing, as I mentioned - in order to comply with their license from the music industry.

The second is that - at least through the site's own web-based UI and from reading what they say in their API docs, the listener should not be presented with a list of the songs - the songs should be played one at a time and the user should only be able to skip songs a limited number of times. In other words, in the Plex UI we should not see a list of individual songs, we should instead see a list of "mixes" or "playlists" if you will, and when the user selects one, the songs that comprise the playlist proceed to play, but the user most likely will not be allowed to skip songs.

I think what I want / need to do is to have each mix/playlist be a TrackObject, which in turn contains a MediaObject, and that in turn contains a list of PartObjects, each of which has the URL to one of the .m4a files that comprises the mix. If I do it properly, the PartObjects will get the URL from a callback function which returns the URL immediately but spawns the thread with the 30-second delay to "phone home" to the parent web site. In any case, if that doesn't work I think I'll need to wait for Plex's plugin framework to be more advanced.


I think your solution should work in theory. Generally speaking, TrackObjects are intended to represent individual songs or podcasts. I don't see any reason that you couldn't use it for the entire playlist in this case except that I'm not sure that PartObjects can be used within a TrackObject. It may or may not work for some or all clients. I look forward to seeing what you get going.


So basically, adding a bunch of part objects (.m4a files) to a media object, adding that media object to a track object and then putting the track object in the menu so it can be played, doesn't seem to quite work (at least running Plex client on a Windows machine where the Plex server is also located). What happens is it plays about 5 seconds of one song, silence for a second or two, then maybe 7 seconds of the same song or another song, then more brief silence, then maybe 10 seconds of another song, and on and on. Maybe it wasn't intended to be used this way, but then on the other hand I'm not quite certain why these objects allow multiple parts to be added if its not for something like this.

Also going to try a slight different approach. I'm going to put each song in a part object, then for each song make a media object and add the corresponding part object to it. Then I am going to create a single track object and add all the media objects to it. Hopefully that will give better results.


I'm not entirely surprised that the stacked part objects within a TrackObject don't work as you hoped. I'm am surprised by the behaviors you describe. To be honest, I would expect it to either work or not, rather than the erratic playback you experienced.
I would be willing to bet that using separate MediaObjects for each song all within the same trackObect won't provide the behaviour you want. The intended behavior for multiple MediaObjects within the same object is to provide clients with a selection of interchangeable options, so that it can select the best version of a media item to playback based on its' settings and capabilities. I'm pretty sure that no client will play them progressively. To be honest, if one did, I think the Plex Devs would consider it a bug and want to "fix" that behaviour.


So I decided to try an entirely different approach. I checked and found that the target web site plays their mixes using a .swf file. So I managed to create the beginnings of a site configuration to try and play the songs that way (via WebVideoURL object). And, the good news is, that the songs actually play within the Plex Client. For me, this offers the advantage that I don't have to "phone home" to their web site 30 seconds after the song starts playing, since, presumably, their own flash player does that for me. But, the bad news is that the on-screen behavior in the Plex client is less than satisfactory. It doesn't act as if its playing a song (no visualizations - not surprising since WebVideoURL object seems designed to play video) - but it doesn't act as if its playing a video either. Instead, the menu remains on screen with the "loading" message present. Is there any way around this?

Good question… Are you wrapping the WebVideoURL inside a TrackObject? I think you still need to let the player know that it should be expecting just the audio rather than audio and video.



Yes, I used a TrackObject. My thinking was along the same lines as yours - that there should be a way to specify audio-only. I thought that there was, but if there is I can't seem to find it in the docs now. Any ideas?

Not at the moment. As much as I hate Flash, it really seems like you're on the right track. I'll have to get back to you on that.

Turns out, the mechanism for handling Flash is video only. There is no “audio-only” setting. So it looks like you’re kinda stuck choosing the least unsavory problem to ignore for the time being. Sorry :frowning:


Thanks. Is there an appropriate place to post plugin framework feature requests? Also, do you know if its possible to pass the URL to a playlist file (like an .m3u file) instead of the URL to a single piece of media?


This forum is probably the best place to make feature requests for the plugin framework. I would suggest a new thread of course ;)
I'm not entirely sure about .m3u files, I know that it's possible to pass an .m3u8 url using the HTTPLiveStreamURL() function. I *think* that would probably work a .m3u file as well but I'm not familiar with the differences between m3u and m3u8 and how PMS and/or the clients would handle them.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.