Problems with PHT and audio streams

I've been really struggling with getting my channel to work on PHT (only tested on Mac, latest plexpass), despite that it works on Plex/Web and Android.

 

Long story short, it's probably best to just show my code and some examples and kindly ask if someone would like to take a look at it. I've tried so many variants now with both direct aac and mp3 streams and now finally using HLS.

 

Here is my URL service code:

LIVE_URL_JSON = 'http://v7.psapi.nrk.no/mediaelement/%s'
LIVE_RADIO_BASEURL = 'http://radio.nrk.no/direkte/'

def MetadataObjectForURL(url):
Log.Debug(‘NRK: MetadataObjectForURL called for %s’ % url)
channel = url.replace(LIVE_RADIO_BASEURL,‘’)
audio_json = JSON.ObjectFromURL(LIVE_URL_JSON % channel, headers={‘User-Agent’:‘Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25’})
return TrackObject(
title = audio_json[‘title’],
summary = audio_json[‘description’],
thumb = “”)

def MediaObjectsForURL(url):
Log.Debug("NRK: Adding media object for live radio stream: " + url)
channel = url.replace(LIVE_RADIO_BASEURL,‘’)
audio_url = JSON.ObjectFromURL(LIVE_URL_JSON % channel, headers={‘User-Agent’:‘Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25’})[‘mediaUrl’]
Log.Debug(‘NRK: Found audio url %s’ % audio_url )
mobjects =
liveurl = (audio_url)
mobjects.append(MediaObject(
parts = [PartObject(key=HTTPLiveStreamURL(liveurl))],
optimized_for_streaming = True,
audio_channels = 2))
return mobjects 

This is a result of testing my url service: lookup-test.xml (972 Bytes)

 

And here is the m3u8 I'm currently working with: master.m3u8.txt (592 Bytes)

 

For the MediaObject, I've tried setting many parameters manually, such as audio_codec and container, with and without HTTPLiveStreamURL etc.

 

The log from PHT repeats a lot of when trying to play an item

 

14:19:06 T:4462026752  NOTICE: Thread MediaDecision start, auto delete: false

14:19:06 T:140735166722432   ERROR: CAudioDecoder: Unable to Init Codec while loading file http://nrkradio-f.akamaihd.net/i/ostlandssendingen_0@4273/master.m3u8
14:19:06 T:140735166722432 WARNING: PAPlayer::QueueNextFileEx - Failed to create the decoder

 

I'm out of alternatives and suggetions, maybe someone here can take a quick look?

 

The log of commits in the liveradio branch show some stuff I've already tried.

That's a tricky one. I would have expected PHT to handle it as well the Plex/Web and Android clients. I would suggest one change for the sake of structuring the code and maybe it will fix the PHT issue too. It looks like you're making at least one HTTP request (JSON.ObjectFromURL) in the MediaObjectsForURL() function. That is discouraged because it slows down the loading of lists of media. For example, if you have a list of 20 radio feeds, you would have to wait for all 20 MediaObjectsForURL() functions to make their HTTP requests and return the results before the directory could load. The solution is to handle the necessary HTTP request(s) in a callback which is only executed when the client makes the Play request. An example that comes to mind is the NHL plugin, here. For your situation, I would recommend separating the code like so:

def MediaObjectsForURL(url):
    Log.Debug("NRK: Adding media object for live radio stream: " + url)
    channel = url.replace(LIVE_RADIO_BASEURL,'')
    mobjects = []
    mobjects.append(MediaObject(
    parts = [PartObject(key=HTTPLiveStreamURL(Callback(PlayLiveStream, channel=channel)))],
      optimized_for_streaming = True,
      audio_channels = 2))
    return mobjects

@indirect
def PlayLiveStream(channel):
audio_url = JSON.ObjectFromURL(LIVE_URL_JSON % channel, headers={‘User-Agent’:‘Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25’})[‘mediaUrl’]
Log.Debug(‘NRK: Found audio url %s’ % audio_url )
return IndirectResponse(TrackObject, key=audio_url)

For your situation, I would recommend separating the code like so:

Thanks, Mikedm139! Yeah, I've been refactoring so many times now it seems I suddenly ended up with doing http requests there as well, but anyway, originially I was doing it the callback way (with a Redirect), then I found out about @indirect and IndirectResponse and tried that, and then I finally tried without a callback.

I'm guessing you are the same Mike as on the plugin dev. chat so as you suggested there; PHT does indeed play it if I change all my TrackObjects to VideoClipObjects ..

Interesting. That sounds like PHT doesn’t know how to deal with an m3u8 for audio only media objects. If the @indirect/IndirectResponse change works in your other clients, I would suggest leaving the code that way and we’ll have to try to get a fix included in PHT.

For anyone coming here with the same problem, this issue was resolved by adding ext = 'ts' to the callback like so:

parts = [PartObject(key=HTTPLiveStreamURL(Callback(PlayLiveStream, channel=channel, ext = 'ts')))],

@indirect/IndirectResponse seems to work fine on both Android and Plex/Web so I kept that in.

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