Get MediaItem object from a MediaItemId (Guid) (1 Viewer)

McGoober

Retired Team Member
  • Premium Supporter
  • August 13, 2006
    122
    105
    Cambridge, UK
    Home Country
    United Kingdom United Kingdom
    I'm coding against IMediaLibrary in a plugin. I have exposed MediaItem.MediaItemId (guid) to a remote application as a unique reference to a media item, but when that app calls back again with this guid I want to turn it back into a MediaItem object. Doing a search is the only way I can think of doing it, but I can't figure out the filter I need since there doesn't seem to be an attribute I can use.


    What I want to do is...

    public MediaItem GetItemFromMediaItemId(Guid ObjectId)
    {
    var library = ServiceRegistration.Get<IMediaLibrary>();
    return library.GetMediaItem(ObjectId, necessaryMIATypeIDs, optionalMIATypeIDs);
    }
     

    Albert

    MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    46
    Freiburg im Breisgau, Germany
    Home Country
    Germany Germany
    AW: Get MediaItem object from a MediaItemId (Guid)

    Is it a sort of playlist what you're exposing? You can use IList<MediaItem> IMediaLibrary.LoadCustomPlaylist(IList<Guid> mediaItemIds, IEnumerable<Guid> necessaryMIATypes, IEnumerable<Guid> optionalMIATypes) or please describe why you need to expose the reference to that item.
     

    McGoober

    Retired Team Member
  • Premium Supporter
  • August 13, 2006
    122
    105
    Cambridge, UK
    Home Country
    United Kingdom United Kingdom
    I'm developing a UPNP DLNA plugin. I need to expose to the connecting device some form of unique id so that the device and the plugin can keep track of where in the media tree the device is. I was thinking of doing this with the media item ID (GUID). This way I know what the child items are by calling library.Browse, but the other thing the device could ask for is "give me more information about this item", and for that I need to turn a media item guid back into a MediaItem object.

    Example...
    So the connecting device might say, give me all items from the root node, and I return..

    var library = ServiceRegistration.Get<IMediaLibrary>();
    var shares = library.GetShares(null);
    var result = from share in shares select library.LoadItem(share.Value.SystemId, share.Value.BaseResourcePath, necessaryMiaTypes, null).MediaItemId;

    The connecting device might then say, give me more information about item: 466bc397-d646-4f3d-bca6-0de2e7ce38ae
    I want to load the media item to get a MediaItem object again.

    Guid mediaItemGuid = new Guid("466bc397-d646-4f3d-bca6-0de2e7ce38ae");
    var library = ServiceRegistration.Get<IMediaLibrary>();
    var item = library.GetMediaItem(mediaItemGuid, necessaryMIATypeIDs, optionalMIATypeIDs);

    I hope that makes more sense :)

    The device could return me any media item and would be of any aspect.
     

    Albert

    MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    46
    Freiburg im Breisgau, Germany
    Home Country
    Germany Germany
    AW: Get MediaItem object from a MediaItemId (Guid)

    Cool, a UPnP/AV MediaServer! :)

    Ok, to achieve that, you can call the method I said above: IList<MediaItem> IMediaLibrary.LoadCustomPlaylist(IList<Guid> mediaItemIds, IEnumerable<Guid> necessaryMIATypes, IEnumerable<Guid> optionalMIATypes). It would also be possible to write an extra method for that in the MediaLibrary, something like MediaItem IMediaLibrary.LoadMediaItem(Guid mediaItemId, IEnumerable<Guid> necessaryMIATypes, IEnumerable<Guid> optionalMIATypes). We can decide that later, when you're finished. Until you're finished, you can use the LoadCustomPlaylist method. You could also write an extension method for the MediaLibrary with the new signature and we replace it later with the final method.
     

    McGoober

    Retired Team Member
  • Premium Supporter
  • August 13, 2006
    122
    105
    Cambridge, UK
    Home Country
    United Kingdom United Kingdom
    Super, that's just what I wanted :D
    Extension method sound like a good plan.

    Just as an aside... I was playing with the code a few nights ago when my wife was watching a DVD on my sony DLNA compliant player. I noticed the next night that it showed my MediaPortal 2 upnp device and I was able to browse some of the shares from the media library... cool hu?, lots of work to go still.
     

    McGoober

    Retired Team Member
  • Premium Supporter
  • August 13, 2006
    122
    105
    Cambridge, UK
    Home Country
    United Kingdom United Kingdom
    Thanks all, LoadCustomPlaylist() works a treat.
    For completeness of this thread, here is the extension method I used.

    Code:
    public static MediaItem GetMediaItem(this IMediaLibrary mediaLibrary, Guid mediaItemId, IEnumerable<Guid> necessaryMIATypes, IEnumerable<Guid> optionalMIATypes)
    {
        var items = mediaLibrary.LoadCustomPlaylist(new List<Guid>() {mediaItemId}, necessaryMIATypes, optionalMIATypes);
        return items.Count > 0 ? items[0] : null;
    }
    So browsing the MediaPortal 2 Media Library works from a DLNA device, now on to streaming the content :D
     

    Users who are viewing this thread


    Write your reply...
    Top Bottom