Init() public method

public Init ( MediaItem mediaItem ) : bool
mediaItem MediaItem
return bool
コード例 #1
0
        public IPlayer GetPlayer(MediaItem mediaItem)
        {
            string mimeType;
            string title;

            if (!mediaItem.GetPlayData(out mimeType, out title))
            {
                return(null);
            }

            PlaylistItem item = mediaItem as PlaylistItem;

            if (item != null && item.InputStreamSite != null)
            {
                Dictionary <string, string> properties;
                if (item.InputStreamSite.GetStreamProperties(item.VideoInfo, out properties))
                {
                    // Replace raw url / token source by resolved stream url
                    var resourceAccessor = new RawUrlResourceAccessor(properties["inputstream.streamurl"]);
                    IList <MultipleMediaItemAspect> providerResourceAspects;
                    MediaItemAspect.TryGetAspects(item.Aspects, ProviderResourceAspect.Metadata, out providerResourceAspects);
                    MultipleMediaItemAspect providerResourceAspect = providerResourceAspects.First();
                    String raPath = resourceAccessor.CanonicalLocalResourcePath.Serialize();
                    providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH, raPath);

                    IResourceLocator  locator = mediaItem.GetResourceLocator();
                    InputStreamPlayer iplayer = (false) ?
                                                new InputStreamDownloader(@"F:\Capture\Dump.mkv") :
                                                new InputStreamPlayer();
                    try
                    {
                        InitOnline(iplayer, properties);
                        iplayer.SetMediaItem(locator, title);

                        if (iplayer.DecryptError)
                        {
                            throw new Exception("Decrypting by InputStream failed.");
                        }

                        return(iplayer);
                    }
                    catch (Exception ex)
                    {
                        ServiceRegistration.Get <ILogger>().Warn("Error playing media item '{0}': {1}", locator, ex.Message);
                        iplayer.Dispose();
                    }
                }
            }

            // Also try browser player as fallback if InputStream decoding failed
            if (mimeType == WebBrowserVideoPlayer.ONLINEVIDEOSBROWSER_MIMETYPE)
            {
                var player = new WebBrowserVideoPlayer();
                if (!player.Init(mediaItem))
                {
                    player.Dispose();
                    return(null);
                }
                return(player);
            }

            return(null);
        }
コード例 #2
0
        public IPlayer GetPlayer(MediaItem mediaItem)
        {
            string mimeType;
            string title;
            if (!mediaItem.GetPlayData(out mimeType, out title))
                return null;

            PlaylistItem item = mediaItem as PlaylistItem;
            if (item != null && item.InputStreamSite != null)
            {
                Dictionary<string, string> properties;
                if (item.InputStreamSite.GetStreamProperties(item.VideoInfo, out properties))
                {
                    // Replace raw url / token source by resolved stream url
                    var resourceAccessor = new RawUrlResourceAccessor(properties["inputstream.streamurl"]);
                    IList<MultipleMediaItemAspect> providerResourceAspects;
                    MediaItemAspect.TryGetAspects(item.Aspects, ProviderResourceAspect.Metadata, out providerResourceAspects);
                    MultipleMediaItemAspect providerResourceAspect = providerResourceAspects.First();
                    String raPath = resourceAccessor.CanonicalLocalResourcePath.Serialize();
                    providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH, raPath);

                    IResourceLocator locator = mediaItem.GetResourceLocator();
                    InputStreamPlayer iplayer = (false) ?
                        new InputStreamDownloader(@"F:\Capture\Dump.mkv") : 
                        new InputStreamPlayer();
                    try
                    {
                        InitOnline(iplayer, properties);
                        iplayer.SetMediaItem(locator, title);

                        if (iplayer.DecryptError)
                            throw new Exception("Decrypting by InputStream failed.");

                        return iplayer;
                    }
                    catch (Exception ex)
                    {
                        ServiceRegistration.Get<ILogger>().Warn("Error playing media item '{0}': {1}", locator, ex.Message);
                        iplayer.Dispose();
                    }
                }
            }

            // Also try browser player as fallback if InputStream decoding failed
            if (mimeType == WebBrowserVideoPlayer.ONLINEVIDEOSBROWSER_MIMETYPE)
            {
                var player = new WebBrowserVideoPlayer();
                if (!player.Init(mediaItem))
                {
                    player.Dispose();
                    return null;
                }
                return player;
            }

            return null;
        }