JSON - Playing a song by ID
#1
Good day !

I know this might sound really simple, but for some reason it simply doesn't work :/ I've built an app that searches for songs and returns a list of them, then I'd like to be able to either queue or play a song by sending back the ID of the song. Sounds straight-forward. I'm using the .net wrapper (XbmcJson) which turns commands to/from json, so here's what the code looks like in there:

Code:
public void Add(string file, int? songId, int? artistId, int? albumId)
        {
            var args = new JObject();

            if (file != null)
                args.Add(new JProperty("file", file));
            if (songId != null)
                args.Add(new JProperty("songid", songId));
            if (artistId != null)
                args.Add(new JProperty("artistid", artistId));
            if (albumId != null)
                args.Add(new JProperty("albumid", albumId));

            Client.Invoke("AudioPlaylist.Add", args);
        }

So I simply pass in "null, {id}, null, null", which means it'll send out a command to add the track to the playlist. I first clear the playlist, then add the track, then hit play as there didn't seem to be a "play" method in the wrapper api I'm using (I've already changed a bunch of things in it, so if there's a better way I don't mind adding the code).

Anybody know why that wouldn't work ? I've also tried sending in the file path (although that's kind of an ugly solution I'd like to avoid because the client doesn't have the full path, and when the ID gets sent it, I then have to re-query for the path, too many roundtrips).

Thanks,
Eric.

KODI:
Windows 10, 32 GB of ram, AMD Phenom X6 @ 2.80 ghz, Using onboard video card with HDMI out
Reply
#2
What do you mean by "then hit play"? What version of XBMC are you using?
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#3
Sorry lol. I mean

Code:
XbmcProvider.AudioPlaylist.Clear();
            XbmcProvider.AudioPlaylist.Add(null, song.SongId, null, null);
            XbmcProvider.AudioPlaylist.Play();

So clear the list, add the track, send play command on playlist.

This is using Eden, 11.8 I think it is (not at home right now, but I'm pretty sure that's what it is).
KODI:
Windows 10, 32 GB of ram, AMD Phenom X6 @ 2.80 ghz, Using onboard video card with HDMI out
Reply
#4
Bump Smile

Anybody have an example of how to do this ? I can rework the wrapper's code no problem.

Thanks,
Eric.
KODI:
Windows 10, 32 GB of ram, AMD Phenom X6 @ 2.80 ghz, Using onboard video card with HDMI out
Reply
#5
Code:
Clear playlist:
{"jsonrpc": "2.0", "id": 0, "method": "Playlist.Clear", "params": {"playlistid": 0}}

Add to playlist:
{"jsonrpc": "2.0", "id": 1, "method": "Playlist.Add", "params": {"playlistid": 0, "item": {"songid": 10}}}

Play playlist:
{"jsonrpc": "2.0", "id": 2, "method": "Player.Open", "params": {"item": {"playlistid": 0}}}

Something like that...
I did not test it tho.

Image
Reply

Logout Mark Read Team Forum Stats Members Help
JSON - Playing a song by ID0