Retrieve duration of items loaded in a playlist
#1
Hello Community,

I'm looking for a way to get the duration of items that are loaded into a playlist. I have several songs loaded into the current playlist, and I want to be able to retrieve the duration of each item. The media items that I have do not have a "duration" entry in the meta data.

If I look in the "Now Playing" window in XBMC, the data is available. XBMC will display the duration of each item. However, the "Playlist.GetItems" method only returns the metadata in the file - it does not return the duration that XBMC clearly has. Is there any way I can access the actual duration of the song as discovered by XBMC? This is critical to my application.

Thanks
Reply
#2
Edit: This seems to only work if added music is not file based (ie item added by 'file', or 'directory'). Sorry.

There is a way to get the duration or runtime from the items in the current playlist.

These are some working examples from my web interface.

For music playlist:
Code:
{"jsonrpc":"2.0","method":"Playlist.GetItems","params":{"playlistid":0,"properties":["title","artist","genre","album","file","duration","thumbnail"]},"id":1}

for video playlist:
Code:
{"jsonrpc":"2.0","method":"Playlist.GetItems","params":{"playlistid":1,"properties":["title","artist","genre","album","file","runtime","thumbnail"]},"id":2}

In the returned data for the music playlist look at the "duration" field. With the returned data for the video playlist look at the "runtime" field.
I am an expert at acting like an expert ---- WC Fields.

XBMC Web Control Interface - https://github.com/mthiels/webinterface.xrc
Reply
#3
I appreciate the reply.

This doesn't work however if the files themselves do not already have the "duration" tag in them. When I call the code you posted with a loaded playlist, I get

Code:
"type":"unknown"

for the duration field. Yet, even still, XBMC knows how long each file is. There must be some method that it calls internally do get this information, probably by parsing the media file itself. Is there any way to have access to that function so that I can return the duration data for my application as well?
Reply
#4
When I add the media file to the playlist as a 'file' or 'directory' then it looks like the runtime field is not being populated.
Code:
{"jsonrpc":"2.0","method":"Playlist.Add","params":{"playlistid":0,"item":{"file":"C:\\xxxx\\musicfile.mp3"}},"id":1}

When I add media files to the playlist using information retrieved from the library then the runtime field is populated.
Code:
{"jsonrpc":"2.0","method":"Playlist.Add","params":{"playlistid":0,"item":{"songid":3985}},"id":1}

More than likely XBMC is not populating the information since the media file is being added as a file.
I am an expert at acting like an expert ---- WC Fields.

XBMC Web Control Interface - https://github.com/mthiels/webinterface.xrc
Reply
#5
That is promising information. I wonder if you could help me fill in the gaps though. For my application, I am using XBMC as a media player which is part of a much larger application. Clients will be able to come, bringing their own media (which may or may not be tagged), and should be able to play it via XBMC. I don't need most information. But I do need duration. I'm doing everything programmatically. Is there a way then to add songs to the library on the fly so that I can retrieve the duration information? And the icing on top would be a cleanup method to undo that....
Reply
#6
You can rescan the music library at any time. When the user adds music you can rescan at that point. When the rescan is done the information should be usable.

Code:
{"jsonrpc":"2.0","method":"AudioLibrary.Scan","id":1}

Just know that the first time scanning a large music database can take a while, incremental library scans don't take much time.
I am an expert at acting like an expert ---- WC Fields.

XBMC Web Control Interface - https://github.com/mthiels/webinterface.xrc
Reply
#7
What ID3 tags can we use to make the "duration" item work? I tried adding TLEN tags to the file, and that did nothing. XBMC still cannot determine the duration of a song...
Reply

Logout Mark Read Team Forum Stats Members Help
Retrieve duration of items loaded in a playlist1