unable to stop RTMP live stream

I’m using RTMP to stream live radio from SR (Swedish Radio).

I build an ObjectContainer with all available live radio channels. Once one channel is selected the live radio stream start without problem. However, whenever I want to stop the live stream (by for example pressing esc), Plex will stop the current live stream but start the next RTMP stream in the ObjectContainer. So it is never possible to stop the live streaming.



This is how the media is added to the ObjectContainer:



media = MediaObject(protocols = Protocol.RTMP, audio_codec = AudioCodec.AAC, parts = [ PartObject(key = RTMPVideoURL(serverURL, clip = clipURL, height = None, width = None, live = True)) ])

track = TrackObject(title = ch_name, key = Callback(LiveChannelInfo,name=ch_name), rating_key = MUSIC_PREFIX + “/live/” + clipURL, thumb = ch_thumb, art = R(ART_DIREKT))



track.add(media)

dir.add(track)



From the Plex Media Server.log I can find the following when I try to stop the live stream:

Jul 27, 2012 21:43:16 [0xb0a25000] DEBUG - WebKit: Sending line: STOP

Jul 27, 2012 21:43:16 [0xb0a25000] DEBUG - WebKit: Stream closed.

Jul 27, 2012 21:43:16 [0xb0a25000] DEBUG - Request: GET /:/progress?key=%2fmusic%2fsverigesradioplay%2flive%2fp1%2daac%2d192&identifier=com.plexapp.plugins.sverigesradioplay&time=49534&state=stopped [127.0.0.1:62519] (2 live)

Jul 27, 2012 21:43:16 [0xb0a25000] DEBUG - * key => /music/sverigesradioplay/live/p1-aac-192

Jul 27, 2012 21:43:16 [0xb0a25000] DEBUG - * identifier => com.plexapp.plugins.sverigesradioplay

Jul 27, 2012 21:43:16 [0xb0a25000] DEBUG - * time => 49534

Jul 27, 2012 21:43:16 [0xb0a25000] DEBUG - * state => stopped

Jul 27, 2012 21:43:16 [0xb0a25000] DEBUG - WebKit: Sending line: STOP

Jul 27, 2012 21:43:16 [0xb0a25000] DEBUG - WebKit: Stream closed.

Jul 27, 2012 21:43:16 [0xb0a25000] DEBUG - WebKit: Stream closed.

Jul 27, 2012 21:43:16 [0xb0e35000] DEBUG - Request: GET /video/:/webkit?url=http%3A%2F%2Fwww.plexapp.com%2Fplayer%2Fplayer.php%3Furl%3Drtmp%253A%2F%2Frtmp-live.sr.se%2Fwebbradio%2Fkanaler%26live%3Dtrue%26clip%3Dp2-aac-192&prefix=/music/sverigesradioplay [127.0.0.1:62520] (1 live)

Jul 27, 2012 21:43:16 [0xb0e35000] DEBUG - * url => http://www.plexapp.com/player/player.php?url=rtmp%3A//rtmp-live.sr.se/webbradio/kanaler&live=true&clip=p2-aac-192

Jul 27, 2012 21:43:16 [0xb0e35000] DEBUG - * prefix => /music/sverigesradioplay

Jul 27, 2012 21:43:16 [0xb0e35000] DEBUG - WebKit: [plexapp.com/player/player.php?url=rtmp%3A//rtmp-live.sr.se/webbradio/kanaler&live=true&clip=p2-aac-192]

Jul 27, 2012 21:43:16 [0xb0e35000] DEBUG - Found corresponding plug-in: /Users/media/Library/Application Support/Plex Media Server/Plug-in Support/Data/com.plexapp.plugins.sverigesradioplay

Jul 27, 2012 21:43:16 [0xb0e35000] DEBUG - WebKit: Resetting to state playing.

Jul 27, 2012 21:43:16 [0xb0e35000] DEBUG - Using /Users/media/Library/Application Support/Plex Media Server/Plug-ins/SiteConfigurations.bundle/Contents/Resources/Plex.xml with score of -960.

Jul 27, 2012 21:43:16 [0xb0e35000] DEBUG - Setting low latency option for two-way stream.

Jul 27, 2012 21:43:16 [0xb0e35000] DEBUG - Beginning read from two-way stream.

Jul 27, 2012 21:43:16 [0xb0e35000] DEBUG - WebKit: Sending line: HELLO

Jul 27, 2012 21:43:16 [0xb0fbb000] DEBUG - Request: GET /:/progress?key=%2fmusic%2fsverigesradioplay%2flive%2fp2%2daac%2d192&identifier=com.plexapp.plugins.sverigesradioplay&time=217&state=playing [127.0.0.1:62522] (2 live)

Jul 27, 2012 21:43:16 [0xb0fbb000] DEBUG - * key => /music/sverigesradioplay/live/p2-aac-192

Jul 27, 2012 21:43:16 [0xb0fbb000] DEBUG - * identifier => com.plexapp.plugins.sverigesradioplay

Jul 27, 2012 21:43:16 [0xb0fbb000] DEBUG - * time => 217

Jul 27, 2012 21:43:16 [0xb0fbb000] DEBUG - * state => playing



Is there anything wrong in how I add Media to the ObjectContainer or this a known issue?

Nothing in your code snippet jumps out at me as being “wrong”. Is the full code available on github (or similar)?

I haven’t tried using RTMP for audio only streams. I’m not sure if that could be related to your issue or not.

I’m about to make it available on github.



The source site is also offering live streaming using MP3 or ACC but I don’t get those to work at all in Plex. Is it supported to use MP3 or ACC for live streaming?



That is a very good question. I honestly don't know. I'll see what I can find out about it.


If you're doing your testing using the Plex desktop client, and I assume you are, it requires an extra ("ext") argument be passed when adding audio track objects. This is to tell the player what type of file it's receiving. Don't ask me why but, apparently the player can't figure out based on the actual file extension so we need to tell it.
If you're using the 2.0 version of the plugin framework, [here's](http://forums2.plexapp.com/index.php/topic/12088-music-plugin-problem/page__p__71748#entry71748) an example of how to implement it.
If you're using the 2.1 version of the plugin framework, the [freakonomics url service](https://github.com/plexinc-plugins/Services.bundle/blob/master/Contents/Service%20Sets/com.plexapp.plugins.freakonomics/URL/Freakonomics/ServiceCode.pys#L18) is a fairly simple example of how to do it. The [associated plugin](https://github.com/plexinc-plugins/Freakonomics.bundle/blob/master/Contents/Code/__init__.py) is also a decent place to look for comparison to your own code.

Thanks a lot! I will try it out.

I tried you solution, but it does not work.

I get the following error in the Plex.log:



21:04:21 T:2953318400 M: 0% NOTICE: Plex Media Server Queue: http://127.0.0.1:32400/:/progress?key=%2Fmusic%2Fsverigesradioplay%2Flive%2FSR%20Extra11&identifier=com.plexapp.plugins.sverigesradioplay&time=0&state=playing

21:04:21 T:2953318400 M: 0% NOTICE: Plex Media Server Queue: http://127.0.0.1:32400/:/progress?key=%2Fmusic%2Fsverigesradioplay%2Flive%2FSR%20Extra11&identifier=com.plexapp.plugins.sverigesradioplay&time=0&state=stopped

21:04:23 T:2954952704 M: 0% ERROR: MP3Codec: Error reading file

21:04:23 T:2954952704 M: 0% ERROR: CAudioDecoder: Error while decoding 1





I have now made the code available at github SRPlay. The work is based on an old plugin so you will find a lot of code that is not updated to framework version 2.1 yet, but the interesting part is in the function ListenLiveMenu.

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