Notification when PVR channel is changed?
#1
Hi,

I'm writing a small service addon which needs to get notification when playback state changes.

Everything is generally working fine, with one exception: I fail to find a way how to detect switched PVR channels.

I've subclassed xbmc.Player and do get proper notifications when I switch files, i.e. onPlayBackStarted() is called everytime a new file starts playing.

However, this is not the case when I'm playing back Live TV (via the VNSI plugin in my case). onPlayBackStarted() is called the first time I start playing Live TV, but not upon a channel switch. It seems that actually none of the notification methods in Player is called on a channel switch. If I stop and restart Live TV playback, I get the expected notifications onPlayBackStopped and onPlayBackStarted.

Am I overlooking something?

Best Regards,
Olli

Version: Kodi (14.2-RC1 Git:20150311-e7ba06f). Platform: Windows NT x86 32-bit
Full log from test run: http://pastebin.com/Mn2jvGiQ
Reply
#2
I think your best go is to find through the json rpc api which channel is playing, saving it and check the player state in timed intervals. If I recall correctly the id of the channel you're watching will change if the entry in the EPG is different so it might be a little hackish to accomplish that.
I'll try to find a code snipped somewhere that can help you out
Reply
#3
Here is what I have on my backups. I'm pretty sure you can find some of the code here usefull. In this case it tries to find out the details of the channel being played in kodi and tries to match it against all the channels the user has on the pvr. Basically it finds the id of the item being payed and checks which channel has that id. I think you have to do that since the id of channel is not constant (depends on the epg entry of the channel). So for instance if you're watching the news on BBC 1 the id will be different from watching let's say a football match in BBC1.

Code:
#check if any player is active
active_players = xbmc.executeJSONRPC('{"jsonrpc":"2.0","id":1,"method":"Player.GetActivePlayers","params":[]}')
#get playerid
try: playerid = json.loads(active_players)['result'][0]['playerid']
except: playerid = None
if playerid:
    #check current active item on the player
    curr_item = xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "plot", "streamdetails"], "playerid":'+str(playerid)+' }, "id": 1 }')
    #find channel id
    try: chid = json.loads(curr_item)['result']['item']['id']
    except: chid = None
    #find channel plot
    try: ch_plot = json.loads(curr_item)['result']['item']['plot']
    except: ch_plot = None
    #find channel name
    ch_name = json.loads(curr_item)['result']['item']['label']
    #find channel title
    try: ch_title = json.loads(curr_item)['result']['item']['title']
    except: ch_title = None
    #load all channel database
    pvr_channel_list = xbmc.executeJSONRPC('{"jsonrpc":"2.0","id":1,"method":"PVR.GetChannels","params":{"channelgroupid":"alltv","properties":["channel","channeltype"]}}')
    meta = json.loads(pvr_channel_list)
    channels = meta['result']['channels']
    
    #check current playing item against the database of all channels
    for i in range(0,len(channels)):
        if channels[i]['channelid'] == chid:
            idx = i
            break


    #print the channel the user is watching right now...
    if idx: print('the user is watching: %s' % str(channels[idx]))

Hope this helps
Reply

Logout Mark Read Team Forum Stats Members Help
Notification when PVR channel is changed?0