Ejemplo n.º 1
0
        public IPlayer GetPlayer(MediaItem mediaItem)
        {
            string mimeType;
            string title;

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

            IResourceLocator locator    = mediaItem.GetResourceLocator();
            Type             playerType = PlayerRegistration.GetPlayerTypeForMediaItem(locator, mimeType);

            if (playerType == null)
            {
                return(null);
            }
            IInitializablePlayer player = (IInitializablePlayer)Activator.CreateInstance(playerType);

            try
            {
                player.SetMediaItem(locator, title, mediaItem);
            }
            catch (Exception e)
            { // The file might be broken, so the player wasn't able to play it
                ServiceRegistration.Get <ILogger>().Warn("{0}: Unable to play '{1}'", e, playerType, locator);
                IDisposable disposablePlayer = player as IDisposable;
                if (disposablePlayer != null)
                {
                    disposablePlayer.Dispose();
                }
                throw;
            }
            return((IPlayer)player);
        }
Ejemplo n.º 2
0
        public VideoPlayerBuilder()
        {
            _videoPlayerBuilderPluginItemStateTracker = new FixedItemStateTracker("VideoPlayerBuilder - MimeType registration");

            IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>();

            foreach (PluginItemMetadata itemMetadata in pluginManager.GetAllPluginItemMetadata(VIDEOPLAYERBUILDERMIMETYPES_REGISTRATION_PATH))
            {
                try
                {
                    VideoPlayerMimeTypeMapping playerMapping = pluginManager.RequestPluginItem <VideoPlayerMimeTypeMapping>(
                        VIDEOPLAYERBUILDERMIMETYPES_REGISTRATION_PATH, itemMetadata.Id, _videoPlayerBuilderPluginItemStateTracker);
                    if (playerMapping == null)
                    {
                        ServiceRegistration.Get <ILogger>().Warn("Could not instantiate VideoPlayerMimeTypeMapping with id '{0}'", itemMetadata.Id);
                    }
                    else
                    {
                        PlayerRegistration.AddMimeTypeMapping(playerMapping.MimeType, playerMapping.PlayerClass);
                    }
                }
                catch (PluginInvalidStateException e)
                {
                    ServiceRegistration.Get <ILogger>().Warn("Cannot add video player MIME type mapping for {0}", e, itemMetadata);
                }
            }
        }