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

            if (!mediaItem.GetPlayData(out mimeType, out title))
            {
                return(null);
            }
            if (mimeType != "video/livetv")
            {
                return(null);
            }
            IResourceLocator locator = mediaItem.GetResourceLocator();
            LiveTvPlayer     player  = new LiveTvPlayer();

            try
            {
                player.SetMediaItem(locator, title);
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Warn("LiveTvPlayer: Error playing media item '{0}'", e, locator);
                player.Dispose();
                return(null);
            }
            return(player);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the data of the new image to be played.
        /// </summary>
        /// <param name="locator">Resource locator of the image item.</param>
        /// <param name="mediaItemTitle">Title of the image item.</param>
        /// <param name="rotation">Rotation of the image.</param>
        /// <param name="flipX">Flipping in horizontal direction.</param>
        /// <param name="flipY">Flipping in vertical direction.</param>
        public void SetMediaItemData(IResourceLocator locator, string mediaItemTitle, RightAngledRotation rotation, bool flipX, bool flipY)
        {
            if (locator == null)
            {
                lock (_syncObj)
                {
                    DisposeTexture();
                    _currentLocator = null;
                    return;
                }
            }

            Texture          texture;
            ImageInformation imageInformation;

            using (IResourceAccessor ra = locator.CreateAccessor())
            {
                IFileSystemResourceAccessor fsra = ra as IFileSystemResourceAccessor;
                if (fsra == null)
                {
                    return;
                }
                using (Stream stream = fsra.OpenRead())
                    using (Stream tmpImageStream = ImageUtilities.ResizeImage(stream, ImageFormat.MemoryBmp, MAX_TEXTURE_DIMENSION, MAX_TEXTURE_DIMENSION))
                        texture = Texture.FromStream(SkinContext.Device, tmpImageStream, (int)tmpImageStream.Length, 0, 0, 1, Usage.None,
                                                     Format.A8R8G8B8, Pool.Default, Filter.None, Filter.None, 0, out imageInformation);
            }
            lock (_syncObj)
            {
                ReloadSettings();
                _state = PlayerState.Active;

                DisposeTexture();
                _currentLocator = locator;
                _mediaItemTitle = mediaItemTitle;
                _texture        = texture;
                _rotation       = rotation;
                _flipX          = flipX;
                _flipY          = flipY;
                SurfaceDescription desc = _texture.GetLevelDescription(0);
                _textureMaxUV = new SizeF(imageInformation.Width / (float)desc.Width, imageInformation.Height / (float)desc.Height);

                // Reset animation
                _animator.Initialize();

                if (_slideShowTimer != null)
                {
                    _slideShowTimer.Change(_slideShowImageDuration, TS_INFINITE);
                }
                else
                {
                    CheckTimer();
                }
                _playbackStartTime = DateTime.Now;
                if (_pauseTime.HasValue)
                {
                    _pauseTime = _playbackStartTime;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Locates the specified asset and opens a stream to read it using the resource locator
        /// override. If UseDefaultContent is set to true and the resource cannot be found, an
        /// attempt to locate it from default content will be made.
        /// </summary>
        /// <param name="assetName">Asset name</param>
        /// <param name="locatorOverride">Locator to attempt to locate the asset with</param>
        /// <returns>Stream</returns>
        public Stream OpenStream(String assetName, IResourceLocator locatorOverride)
        {
            if (String.IsNullOrEmpty(assetName))
            {
                throw new NullReferenceException("Asset name is not valid");
            }

            IResource resource = null;

            //First try: Try to locate the resource with the override
            resource = locatorOverride.LocateResource(assetName);

            //Second try, if resource is not located then try the default content
            if (resource == null)
            {
                if (!_useDefault)
                {
                    throw new ResourceNotFoundException(String.Format("Resource {0} could not be found", assetName));
                }
                try {
                    return(Engine.RenderSystemProvider.DefaultContent.OpenStream(assetName));
                } catch (Exception e) {
                    throw new ResourceNotFoundException(String.Format("Resource {0} could not be found", assetName), e.InnerException);
                }
            }

            return(resource.OpenStream());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reads all tag images and caches them in the <see cref="IFanArtCache"/> service.
        /// </summary>
        /// <param name="mediaItemLocator"><see cref="IResourceLocator>"/> that points to the file.</param>
        /// <param name="mediaItemId">Id of the media item.</param>
        /// <param name="title">Title of the media item.</param>
        /// <returns><see cref="Task"/> that completes when the images have been cached.</returns>
        protected async Task ExtractFanArt(IResourceLocator mediaItemLocator, Guid mediaItemId, string title, IDictionary <Guid, IList <MediaItemAspect> > aspects)
        {
            try
            {
                //File based access
                using (IResourceAccessor mediaItemAccessor = mediaItemLocator.CreateAccessor())
                    using (LocalFsResourceAccessorHelper rah = new LocalFsResourceAccessorHelper(mediaItemAccessor))
                        using (rah.LocalFsResourceAccessor.EnsureLocalFileSystemAccess())
                        {
                            if (MKV_EXTENSIONS.Contains(ResourcePathHelper.GetExtension(mediaItemLocator.NativeResourcePath.FileName)))
                            {
                                await ExtractMkvFanArt(rah.LocalFsResourceAccessor, mediaItemId, title).ConfigureAwait(false);
                            }
                            if (MP4_EXTENSIONS.Contains(ResourcePathHelper.GetExtension(mediaItemLocator.NativeResourcePath.FileName)))
                            {
                                await ExtractTagFanArt(rah.LocalFsResourceAccessor, mediaItemId, title).ConfigureAwait(false);
                            }

                            //Don't create thumbs if they already exist or if it is a movie (they use posters)
                            var thumbs = ServiceRegistration.Get <IFanArtCache>().GetFanArtFiles(mediaItemId, FanArtTypes.Thumbnail);
                            if (!thumbs.Any() && !aspects.ContainsKey(ThumbnailLargeAspect.ASPECT_ID) && !aspects.ContainsKey(MovieAspect.ASPECT_ID))
                            {
                                await ExtractThumbnailFanArt(rah.LocalFsResourceAccessor, mediaItemId, title, aspects);
                            }
                        }
            }
            catch (Exception ex)
            {
                Logger.Warn("VideoFanArtHandler: Exception while reading MKV tag images for '{0}'", ex, mediaItemLocator.NativeResourcePath);
            }
        }
Ejemplo n.º 5
0
        public IPlayer GetPlayer(MediaItem mediaItem)
        {
            string mimeType;
            string title;

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

            if (InputSourceFactory.CanPlay(locator, mimeType))
            {
                BassPlayer player = new BassPlayer(_pluginDirectory);
                try
                {
                    player.SetMediaItemLocator(locator, mimeType, title);
                }
                catch (Exception e)
                {
                    ServiceRegistration.Get <ILogger>().Warn("BassPlayerPlugin: Error playing media item '{0}'", e, locator);
                    player.Dispose();
                    return(null);
                }
                return(player);
            }
            return(null);
        }
Ejemplo n.º 6
0
        public IPlayer GetPlayer(MediaItem mediaItem)
        {
            string mimeType;
            string title;

            if (!mediaItem.GetPlayData(out mimeType, out title))
            {
                return(null);
            }
            if (Enabled && mimeType == "video/bluray")
            {
                IResourceLocator locator = mediaItem.GetResourceLocator();
                BDPlayer         player  = new BDPlayer();
                try
                {
                    player.SetMediaItem(locator, title);
                }
                catch (Exception)
                {
                    LogError("Error playing media item '{0}'", locator);
                    player.Dispose();
                    return(null);
                }
                return(player);
            }
            return(null);
        }
Ejemplo n.º 7
0
        public Formatter Parse()
        {
            var f = _locatorFactory.CloneForTagLib(_lib);

            if (_initialLocator == null)
            {
                _initialLocator = f.GetNewLocator();
            }
            var formatter = new InternalFormatter(new TagLibParserFactory(new TagLibForParsing(_lib), _expressionLib, f, _tagValidator), _expressionLib, _template, _allowTags, _initialLocator);

            try
            {
                formatter.Parse();
                CreateTemplateProcessorFor(_lib).Process(formatter.ParsedTemplate);
                if (_templateValidator != null)
                {
                    _templateValidator.Validate(formatter.ParsedTemplate);
                }
                CreateTemplateValidatorFor(_lib).Validate(formatter.ParsedTemplate);
            }
            finally
            {
                _templateParsed = formatter.ParsedTemplate;
            }
            return(this);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets all season folder images and caches them in the <see cref="IFanArtCache"/> service.
        /// </summary>
        /// <param name="mediaItemLocator"><see cref="IResourceLocator>"/> that points to the file.</param>
        /// <param name="seasonMediaItemId">Id of the season media item.</param>
        /// <param name="title">Title of the media item.</param>
        /// <param name="seasonNumber">Season number.</param>
        /// <param name="actors">Collection of actor ids and names.</param>
        /// <returns><see cref="Task"/> that completes when the images have been cached.</returns>
        protected async Task ExtractSeasonFolderFanArt(IResourceLocator mediaItemLocator, Guid seasonMediaItemId, string title, int?seasonNumber, IList <Tuple <Guid, string> > actors)
        {
            var seasonDirectory = ResourcePathHelper.Combine(mediaItemLocator.NativeResourcePath, "../");

            try
            {
                FanArtPathCollection paths = null;
                IList <ResourcePath> potentialActorImages = null;
                using (IResourceAccessor accessor = new ResourceLocator(mediaItemLocator.NativeSystemId, seasonDirectory).CreateAccessor())
                    if (accessor is IFileSystemResourceAccessor fsra)
                    {
                        paths = GetSeasonFolderFanArt(fsra, seasonNumber);
                        //See if there's an actor fanart directory and try and get any actor fanart
                        if (actors != null && actors.Count > 0 && fsra.ResourceExists(".actors"))
                        {
                            using (IFileSystemResourceAccessor actorsDirectory = fsra.GetResource(".actors"))
                                potentialActorImages = LocalFanartHelper.GetPotentialFanArtFiles(actorsDirectory);
                        }
                    }

                if (paths != null)
                {
                    await SaveFolderImagesToCache(mediaItemLocator.NativeSystemId, paths, seasonMediaItemId, title).ConfigureAwait(false);
                }
                if (potentialActorImages != null)
                {
                    await SavePersonFolderImages(mediaItemLocator.NativeSystemId, potentialActorImages, actors).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                Logger.Warn("SeriesFanArtHandler: Exception while reading folder images for '{0}'", ex, seasonDirectory);
            }
        }
Ejemplo n.º 9
0
        protected override void UnregisterResource(string name)
        {
            Guard.ArgumentNotNullOrEmpty(name, "name");

            lock (_lock)
            {
                // contains checks
                if (!_resources.ContainsKey(name))
                {
                    throw new KeyNotFoundException(string.Format(RESOURCE_NOTFOUND, typeof(T), name));
                }

                // we get the locator and dispose it to release any resources
                IResourceLocator _locator = _resources[name];
                if (_locator != null)
                {
                    _locator.Dispose();
                }

                // and remove, and change the default resource name
                _resources.Remove(name);
                if (string.Equals(_defaultResourceName, name, StringComparison.InvariantCultureIgnoreCase))
                {
                    _defaultResourceName = null;
                }

                // notify collection changed
                var _collectionChanged = CollectionChanged;
                if (_collectionChanged != null)
                {
                    _collectionChanged(this,
                                       new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, _locator, -1));
                }
            }
        }
Ejemplo n.º 10
0
        protected override void RegisterResourceLocator(IResourceLocator locator, bool isDefault)
        {
            Guard.ArgumentNotNull(locator, "locator");
            Guard.ArgumentNotNullOrWhiteSpace(locator.ResourceName, "locator", RESOURCE_NOTNULLOREMPTY);

            // we get the name
            var _name = locator.ResourceName;

            lock (_lock)
            {
                // and check
                if (_resources.ContainsKey(_name))
                {
                    throw new InvalidOperationException(string.Format(RESOURCE_ALREADYEXISTS, typeof(T).FullName, _name));
                }

                // add the resource
                _resources.Add(_name, locator);
                if (isDefault)
                {
                    _defaultResourceName = _name;
                }

                // notify collection changed
                var _collectionChanged = CollectionChanged;
                if (_collectionChanged != null)
                {
                    _collectionChanged(this,
                                       new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, locator, -1));
                }
            }
        }
Ejemplo n.º 11
0
    /// <summary>
    /// Creates an <see cref="IInputSource"/> object for a given mediaitem.
    /// </summary>
    /// <param name="resourceLocator">Locator instance to the media item to create the input source for.</param>
    /// <param name="mimeType">Mime type of the media item, if present. May be <c>null</c>.</param>
    /// <returns>Input source object for the given <paramref name="resourceLocator"/> or <c>null</c>, if no input source
    /// could be created.</returns>
    public IInputSource CreateInputSource(IResourceLocator resourceLocator, string mimeType)
    {
      if (!CanPlay(resourceLocator, mimeType))
        return null;
      IResourceAccessor accessor = resourceLocator.CreateAccessor();
      IInputSource result;
      AudioCDResourceAccessor acdra = accessor as AudioCDResourceAccessor;
      if (acdra != null)
        result = BassCDTrackInputSource.Create(acdra.Drive, acdra.TrackNo);
      else
      {
        string filePath = accessor.ResourcePathName;
        if (URLUtils.IsCDDA(filePath))
        {
          ILocalFsResourceAccessor lfra = accessor as ILocalFsResourceAccessor;
          if (lfra == null)
            return null;
          result = BassFsCDTrackInputSource.Create(lfra.LocalFileSystemPath);
        }
        else if (URLUtils.IsMODFile(filePath))
          result = BassMODFileInputSource.Create(accessor);
        else
          result = BassAudioFileInputSource.Create(accessor);
        // TODO: Handle web streams when we have resource accessors for web URLs: BassWebStreamInputSource.Create(...);
      }

      accessor.PrepareStreamAccess();

      Log.Debug("InputSourceFactory: Creating input source for media resource '{0}' of type '{1}'", accessor, result.GetType());
      return result;
    }
Ejemplo n.º 12
0
        /// <summary>
        /// Enqueues a play workitem for the given mediaitem.
        /// </summary>
        /// <param name="mediaItem">MediaItem to-be-played item.</param>
        /// <remarks>
        /// The workitem will actually be executed on the controller's mainthread.
        /// </remarks>
        public bool SetMediaItem(MediaItem mediaItem)
        {
            string mimeType;
            string title;

            if (!GetMediaItemPlayData(mediaItem, out mimeType, out title))
            {
                return(false);
            }
            IResourceLocator locator = mediaItem.GetResourceLocator();

            if (!InputSourceFactory.CanPlay(locator, mimeType))
            {
                return(false);
            }

            if (_externalState != PlayerState.Stopped)
            {
                Stop();
            }
            IInputSource inputSource = _inputSourceFactory.CreateInputSource(locator, mimeType);

            if (inputSource == null)
            {
                ServiceRegistration.Get <ILogger>().Warn("Unable to play '{0}'", locator);
                return(false);
            }
            _mediaItemTitle = title;
            _mediaItemId    = mediaItem.MediaItemId;
            _externalState  = PlayerState.Active;
            _controller.MoveToNextItem_Async(inputSource, StartTime.AtOnce);
            return(true);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Sets the media item for the new image to be played.
        /// </summary>
        /// <param name="mediaItem">MediaItem to-be-played item.</param>
        public bool SetMediaItem(MediaItem mediaItem)
        {
            string mimeType;
            string title;

            if (!mediaItem.GetPlayData(out mimeType, out title))
            {
                return(false);
            }
            IResourceLocator locator = mediaItem.GetResourceLocator();

            if (locator == null)
            {
                return(false);
            }
            if (!CanPlay(locator, mimeType))
            {
                return(false);
            }
            RightAngledRotation rotation = RightAngledRotation.Zero;
            bool flipX = false;
            bool flipY = false;

            SetMediaItemData(locator, title, rotation, flipX, flipY);
            return(true);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Initializes a new <see cref="ContentTypeHelper"/> instance
 /// </summary>
 /// <param name="variationHelper">Variations helper</param>
 /// <param name="fieldHelper">Field helper</param>
 /// <param name="resourceLocator">The resource locator</param>
 /// <param name="log">Logging utility</param>
 public ContentTypeHelper(IVariationHelper variationHelper, IFieldHelper fieldHelper, IResourceLocator resourceLocator, ILogger log)
 {
     this.variationHelper = variationHelper;
     this.fieldHelper     = fieldHelper;
     this.resourceLocator = resourceLocator;
     this.log             = log;
 }
Ejemplo n.º 15
0
        public bool NextItem(MediaItem mediaItem, StartTime startTime)
        {
            string mimeType;
            string title;

            if (!mediaItem.GetPlayData(out mimeType, out title))
            {
                return(false);
            }
            IResourceLocator locator = mediaItem.GetResourceLocator();

            if (locator == null)
            {
                return(false);
            }
            IInputSource inputSource = _inputSourceFactory.CreateInputSource(locator, mimeType);

            if (inputSource == null)
            {
                return(false);
            }
            lock (_syncObj)
                _externalState = PlayerState.Active;
            _controller.MoveToNextItem_Async(inputSource, startTime);
            _mediaItemTitle = title; // This is a bit too early because we're not switching to the next item at once, but doesn't matter
            return(true);
        }
Ejemplo n.º 16
0
 public RefreshableResourceTemplate(IResourceLocator locator, IResourceLocatorFactory factory, string name)
 {
     _name    = name;
     _locator = locator;
     _factory = factory;
     LoadResource();
 }
Ejemplo n.º 17
0
        public virtual bool NextItem(MediaItem mediaItem, StartTime startTime)
        {
            string mimeType;
            string title;

            // Only re-use player for multi-part files
            if (!mediaItem.GetPlayData(out mimeType, out title) || mediaItem.MaximumResourceLocatorIndex == 0 && mediaItem.MaximumEditionIndex == 0)
            {
                ServiceRegistration.Get <ILogger>().Debug("VideoPlayer: Can reuse current player only for multi-resource items");
                return(false);
            }
            Stop();

            if (mediaItem.ActiveResourceLocatorIndex > mediaItem.MaximumResourceLocatorIndex)
            {
                return(false);
            }

            // Set new resource locator for existing player, this avoids interim close of player slot
            IResourceLocator resourceLocator = mediaItem.GetResourceLocator();

            ServiceRegistration.Get <ILogger>().Debug("VideoPlayer: Changed resource to index {0}", mediaItem.ActiveResourceLocatorIndex);
            SetMediaItem(resourceLocator, title, mediaItem);
            _isPaused = false;
            return(true);
        }
 public RefreshableResourceTemplate(IResourceLocator locator, IResourceLocatorFactory factory, string name)
 {
     _name = name;
     _locator = locator;
     _factory = factory;
     LoadResource();
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Gets all collection folder images and caches them in the <see cref="IFanArtCache"/> service.
        /// </summary>
        /// <param name="mediaItemLocator"><see cref="IResourceLocator>"/> that points to the file.</param>
        /// <param name="collectionMediaItemId">Id of the series media item.</param>
        /// <param name="title">Title of the media item.</param>
        /// <returns><see cref="Task"/> that completes when the images have been cached.</returns>
        protected async Task ExtractCollectionFolderFanArt(IResourceLocator mediaItemLocator, Guid collectionMediaItemId, string title)
        {
            var collectionDirectory         = ResourcePathHelper.Combine(mediaItemLocator.NativeResourcePath, "../../");
            var centralCollectionDirectory  = ResourcePathHelper.Combine(mediaItemLocator.NativeResourcePath, "../../../" + MOVIESET_FANART_FOLDER);
            var centralCollectionDirectory2 = ResourcePathHelper.Combine(mediaItemLocator.NativeResourcePath, "../../" + MOVIESET_FANART_FOLDER);
            var movieDirectory = ResourcePathHelper.Combine(mediaItemLocator.NativeResourcePath, "../");

            try
            {
                FanArtPathCollection paths = new FanArtPathCollection();
                using (IResourceAccessor accessor = new ResourceLocator(mediaItemLocator.NativeSystemId, centralCollectionDirectory).CreateAccessor())
                    paths.AddRange(GetCollectionFolderFanArt(accessor as IFileSystemResourceAccessor));
                using (IResourceAccessor accessor = new ResourceLocator(mediaItemLocator.NativeSystemId, centralCollectionDirectory2).CreateAccessor())
                    paths.AddRange(GetCollectionFolderFanArt(accessor as IFileSystemResourceAccessor));
                using (IResourceAccessor accessor = new ResourceLocator(mediaItemLocator.NativeSystemId, collectionDirectory).CreateAccessor())
                    paths.AddRange(GetCollectionFolderFanArt(accessor as IFileSystemResourceAccessor));
                using (IResourceAccessor accessor = new ResourceLocator(mediaItemLocator.NativeSystemId, movieDirectory).CreateAccessor())
                    paths.AddRange(GetMovieFolderCollectionFanArt(accessor as IFileSystemResourceAccessor));
                await SaveFolderImagesToCache(mediaItemLocator.NativeSystemId, paths, collectionMediaItemId, title).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Logger.Warn("MovieFanArtHandler: Exception while reading folder images for '{0}'", ex, collectionDirectory);
            }
        }
Ejemplo n.º 20
0
        public IPlayer GetPlayer(MediaItem mediaItem)
        {
            string mimeType;
            string title;

            if (!mediaItem.GetPlayData(out mimeType, out title))
            {
                return(null);
            }
            if (mimeType != LiveTvMediaItem.MIME_TYPE_TV && mimeType != LiveTvMediaItem.MIME_TYPE_RADIO)
            {
                return(null);
            }
            IResourceLocator locator = mediaItem.GetResourceLocator();
            BaseDXPlayer     player  = mimeType == LiveTvMediaItem.MIME_TYPE_TV ? (BaseDXPlayer) new LiveTvPlayer() : new LiveRadioPlayer(true);

            try
            {
                player.SetMediaItem(locator, title);
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Warn("SlimTvPlayerBuilder: Error playing media item '{0}'", e, locator);
                player.Dispose();
                return(null);
            }
            return(player);
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Initializes a new <see cref="ContentTypeHelper"/> instance
 /// </summary>
 /// <param name="variationHelper">Variations helper</param>
 /// <param name="fieldHelper">Field helper</param>
 /// <param name="resourceLocator">The resource locator</param>
 /// <param name="log">Logging utility</param>
 public ContentTypeHelper(IVariationHelper variationHelper, IFieldHelper fieldHelper, IResourceLocator resourceLocator, ILogger log)
 {
     this.variationHelper = variationHelper;
     this.fieldHelper = fieldHelper;
     this.resourceLocator = resourceLocator;
     this.log = log;
 }
Ejemplo n.º 22
0
        public bool NextItem(MediaItem mediaItem, StartTime startTime)
        {
            string mimeType;
            string title;

            if (!mediaItem.GetPlayData(out mimeType, out title))
            {
                return(false);
            }
            IResourceLocator locator = mediaItem.GetResourceLocator();

            if (locator == null)
            {
                return(false);
            }
            if (!CanPlay(locator, mimeType))
            {
                return(false);
            }
            RightAngledRotation rotation = RightAngledRotation.Zero;
            bool            flipX        = false;
            bool            flipY        = false;
            MediaItemAspect imageAspect  = mediaItem[ImageAspect.ASPECT_ID];

            if (imageAspect != null)
            {
                int           orientationInfo = (int)imageAspect[ImageAspect.ATTR_ORIENTATION];
                ImageRotation imageRotation;
                ImageAspect.OrientationToRotation(orientationInfo, out imageRotation);
                rotation = PlayerRotationTranslator.TranslateToRightAngledRotation(imageRotation);
                ImageAspect.OrientationToFlip(orientationInfo, out flipX, out flipY);
            }
            SetMediaItemData(locator, title, rotation, flipX, flipY);
            return(true);
        }
Ejemplo n.º 23
0
        private void ExtractLocalImages(IDictionary <Guid, IList <MediaItemAspect> > aspects, Guid?episodeMediaItemId, Guid?seriesMediaItemId, Guid?seasonMediaItemId, EpisodeInfo episode, SeriesInfo series, SeasonInfo season, IDictionary <Guid, string> actorMediaItems)
        {
            if (BaseInfo.IsVirtualResource(aspects))
            {
                return;
            }

            IResourceLocator mediaItemLocater = GetResourceLocator(aspects);

            if (mediaItemLocater == null)
            {
                return;
            }

            ExtractFolderImages(mediaItemLocater, episodeMediaItemId, seriesMediaItemId, seasonMediaItemId, episode, series, season, actorMediaItems);
            using (IResourceAccessor mediaItemAccessor = mediaItemLocater.CreateAccessor())
            {
                using (LocalFsResourceAccessorHelper rah = new LocalFsResourceAccessorHelper(mediaItemAccessor))
                {
                    using (rah.LocalFsResourceAccessor.EnsureLocalFileSystemAccess())
                    {
                        ExtractMkvImages(rah.LocalFsResourceAccessor, seriesMediaItemId, series);
                    }
                }
            }
        }
Ejemplo n.º 24
0
        public IPlayer GetPlayer(MediaItem mediaItem)
        {
            string mimeType;
            string title;

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

            if (!ImagePlayer.CanPlay(locator, mimeType))
            {
                return(null);
            }
            ImagePlayer player = new ImagePlayer();

            try
            {
                if (!player.NextItem(mediaItem, StartTime.AtOnce))
                {
                    player.Dispose();
                    return(null);
                }
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Warn("ImagePlayerBuilder: Error playing media item '{0}'", e, locator);
                player.Dispose();
                return(null);
            }
            return(player);
        }
Ejemplo n.º 25
0
        private void ExtractLocalImages(IDictionary <Guid, IList <MediaItemAspect> > aspects, Guid?movieMediaItemId, Guid?collectionMediaItemId, string movieName, string collectionName, IDictionary <Guid, string> actorMediaItems)
        {
            if (BaseInfo.IsVirtualResource(aspects))
            {
                return;
            }

            IResourceLocator mediaItemLocater = GetResourceLocator(aspects);

            if (mediaItemLocater == null)
            {
                return;
            }

            ExtractFolderImages(mediaItemLocater, movieMediaItemId, collectionMediaItemId, movieName, collectionName, actorMediaItems);
            using (IResourceAccessor mediaItemAccessor = mediaItemLocater.CreateAccessor())
            {
                using (LocalFsResourceAccessorHelper rah = new LocalFsResourceAccessorHelper(mediaItemAccessor))
                {
                    using (rah.LocalFsResourceAccessor.EnsureLocalFileSystemAccess())
                    {
                        ExtractMkvImages(rah.LocalFsResourceAccessor, movieMediaItemId, movieName);
                    }
                }
            }
        }
Ejemplo n.º 26
0
        public void SetMediaItem(IResourceLocator locator, string mediaItemTitle)
        {
            // free previous opened resource
            FilterGraphTools.TryDispose(ref _resourceAccessor);
            FilterGraphTools.TryDispose(ref _rot);

            _state    = PlayerState.Active;
            _isPaused = true;
            try
            {
                _resourceLocator  = locator;
                _mediaItemTitle   = mediaItemTitle;
                _resourceAccessor = _resourceLocator.CreateAccessor();

                // Create a DirectShow FilterGraph
                CreateGraphBuilder();

                // Add it in ROT (Running Object Table) for debug purpose, it allows to view the Graph from outside (i.e. graphedit)
                _rot = new DsROTEntry(_graphBuilder);

                // Add a notification handler (see WndProc)
                _instancePtr = Marshal.AllocCoTaskMem(4);
                IMediaEventEx mee = _graphBuilder as IMediaEventEx;
                if (mee != null)
                {
                    mee.SetNotifyWindow(SkinContext.Form.Handle, WM_GRAPHNOTIFY, _instancePtr);
                }

                // Create the Allocator / Presenter object
                AddPresenter();

                ServiceRegistration.Get <ILogger>().Debug("{0}: Adding audio renderer", PlayerTitle);
                AddAudioRenderer();

                ServiceRegistration.Get <ILogger>().Debug("{0}: Adding preferred codecs", PlayerTitle);
                AddPreferredCodecs();

                ServiceRegistration.Get <ILogger>().Debug("{0}: Adding source filter", PlayerTitle);
                AddSourceFilter();

                ServiceRegistration.Get <ILogger>().Debug("{0}: Run graph", PlayerTitle);

                //This needs to be done here before we check if the evr pins are connected
                //since this method gives players the chance to render the last bits of the graph
                OnBeforeGraphRunning();

                // Now run the graph, i.e. the DVD player needs a running graph before getting informations from dvd filter.
                IMediaControl mc = (IMediaControl)_graphBuilder;
                int           hr = mc.Run();
                new HRESULT(hr).Throw();

                _initialized = true;
                OnGraphRunning();
            }
            catch (Exception)
            {
                Shutdown();
                throw;
            }
        }
Ejemplo n.º 27
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);
        }
        private void ExtractLocalImages(IDictionary <Guid, IList <MediaItemAspect> > aspects, Guid?albumMediaItemId, IDictionary <Guid, string> artistMediaItems, string albumTitle)
        {
            if (BaseInfo.IsVirtualResource(aspects))
            {
                return;
            }

            IResourceLocator mediaItemLocater = GetResourceLocator(aspects);

            if (mediaItemLocater == null)
            {
                return;
            }

            ExtractFolderImages(mediaItemLocater, albumMediaItemId, artistMediaItems, albumTitle);
            using (IResourceAccessor mediaItemAccessor = mediaItemLocater.CreateAccessor())
            {
                using (LocalFsResourceAccessorHelper rah = new LocalFsResourceAccessorHelper(mediaItemAccessor))
                {
                    using (rah.LocalFsResourceAccessor.EnsureLocalFileSystemAccess())
                    {
                        ExtractFileImages(rah.LocalFsResourceAccessor, albumMediaItemId, albumTitle);
                    }
                }
            }
        }
Ejemplo n.º 29
0
 private static ResourceManager LoadResourceFileWithCache(string filePath, IResourceLocator locator)
 {
     if (!CACHE.ContainsKey(filePath))
     {
         CACHE.Add(filePath, locator.LoadBundle(filePath));
     }
     return(CACHE[filePath]);
 }
Ejemplo n.º 30
0
 public ObjectPathItemLoader(IResourceLocator <DAL.Model, Model> modelLocator,
                             IResourceLocator <Texture, byte[]> textureLocator,
                             IResourceLocator <DAL.Animation, Animation> animationLocator)
 {
     _textureLocator   = textureLocator;
     _modelLocator     = modelLocator;
     _animationLocator = animationLocator;
 }
 /// <summary>
 /// Constructor to inject the view model dependencies
 /// </summary>
 /// <param name="wallPostRepository">Wall post data access</param>
 /// <param name="wallReplyRepository">Wall reply data access</param>
 /// <param name="taxonomyService">Taxonomy service</param>
 /// <param name="resourceLocator">Resource utility</param>
 /// <param name="log">Logging utility</param>
 public WallViewModel(IWallPostRepository wallPostRepository, IWallReplyRepository wallReplyRepository, ITaxonomyService taxonomyService, IResourceLocator resourceLocator, ILogger log)
 {
     this._wallPostRepository = wallPostRepository;
     this._wallReplyRepository = wallReplyRepository;
     this._taxonomyService = taxonomyService;
     this._resourceLocator = resourceLocator;
     this._log = log;
 }
Ejemplo n.º 32
0
 public ParsedTemplate(IResourceLocator locator, IList <ITemplatePart> templateParsed)
 {
     _locator        = locator;
     _templateParsed = templateParsed;
     _context        = templateParsed != null && templateParsed.Count > 0 && templateParsed[0] != null
                    ? templateParsed[0].Context
                    : null;
 }
Ejemplo n.º 33
0
 public ObjectPathItemLoader(IResourceLocator<DAL.Model, Model> modelLocator,
                             IResourceLocator<Texture, byte[]> textureLocator,
                             IResourceLocator<DAL.Animation, Animation> animationLocator)
 {
     _textureLocator = textureLocator;
     _modelLocator = modelLocator;
     _animationLocator = animationLocator;
 }
Ejemplo n.º 34
0
 public ITemplate Handle(string entry, IResourceLocator locator, bool throwException)
 {
     if (throwException || locator.Exists(entry))
         {
             return new RefreshableResourceTemplate(locator, this, entry);
         }
         return null;
 }
Ejemplo n.º 35
0
 public ResourceTemplate(ITagLib lib, IResourceLocator resource, IResourceLocatorFactory factory, string path)
 {
     _lib = lib;
     _path = path;
     _resource = resource;
     _factory = factory;
     Load();
 }
Ejemplo n.º 36
0
 public ITemplate Handle(String entry, IResourceLocator locator, bool throwException)
 {
     if (throwException || locator.Exists(entry))
     {
         return(new FileTemplate(locator, this, locator.PreFixed(entry)));
     }
     return(null);
 }
Ejemplo n.º 37
0
 public DashboardContentProvider(
     IResourceLocator resourceLocator,
     IQueryExecutor queryExecutor
     )
 {
     _resourceLocator = resourceLocator;
     _queryExecutor   = queryExecutor;
 }
Ejemplo n.º 38
0
 public ITagLibParser Construct(ParseHelper helper, IResourceLocator locator)
 {
     var mode = _lib.Mode;
     if(mode==TagLibMode.Strict) return new StrictTagLibParser(_lib, _expressionLib,helper, locator, _factory, _tagValidator);
     if (mode == TagLibMode.StrictResolve) return new StrictResolveTagLibParser(_lib, _expressionLib, helper, locator, _factory, _tagValidator);
     if (mode == TagLibMode.RelaxedResolve) return new RelaxedResolveTagLibParser(_lib, _expressionLib, helper, locator, _factory, _tagValidator);
     if (mode == TagLibMode.IgnoreResolve) return new IgnoreResolveTagLibParser(_lib, _expressionLib, helper, locator, _factory, _tagValidator);
     return null;
 }
Ejemplo n.º 39
0
 public AbstractTagLibParser(TagLibForParsing lib, ExpressionLib expressionLib, ParseHelper helper, IResourceLocator locator, IResourceLocatorFactory factory, ITagValidator tagValidator)
 {
     _lib = lib;
     _expressionLib = expressionLib;
     _helper = helper;
     _locator = locator;
     _factory = factory;
     _tagValidator = tagValidator;
 }
Ejemplo n.º 40
0
        /// <summary>
        /// Creates an empty registry.
        /// </summary>
        public Registry()
        {
            plugins = new Plugins(this);
            components = new Components(this);
            services = new Services(this);
            serviceLocator = new RegistryServiceLocator(this);
            resourceLocator = new RegistryResourceLocator(this);

            dataBox = new LockBox<RegistryData>(new RegistryData());
        }
Ejemplo n.º 41
0
 /// <summary>Creates a list helper</summary>
 /// <param name="contentTypeBuilder">The content Type Builder.</param>
 /// <param name="fieldHelper">Field creator utility</param>
 /// <param name="resourceLocator">The resource locator</param>
 /// <param name="logger">The logger</param>
 /// <param name="listLocator">List locator</param>
 public ListHelper(
     IContentTypeHelper contentTypeBuilder,
     IFieldHelper fieldHelper,
     IResourceLocator resourceLocator,
     ILogger logger,
     IListLocator listLocator)
 {
     this.contentTypeBuilder = contentTypeBuilder;
     this.fieldHelper = fieldHelper;
     this.resourceLocator = resourceLocator;
     this.logger = logger;
     this.listLocator = listLocator;
 }
Ejemplo n.º 42
0
 public ITag Parse(ParseHelper helper, IResourceLocator locator)
 {
     helper.PushNewTokenConfiguration(true, true, null, TagLibConstants.SEPERATORS, null, TagLibConstants.LITERALS,
                                      ResetIndex.CurrentAndLookAhead);
     try
     {
         return Construct(helper, locator).Parse();
     }
     finally
     {
         helper.PopTokenConfiguration(ResetIndex.LookAhead);
     }
 }
Ejemplo n.º 43
0
    public static Type GetPlayerTypeForMediaItem(IResourceLocator locator, string mimeType)
    {
      Type playerType;
	    // When a mimetype is set, try to get the player type for it
      if (mimeType != null && MIMETYPES2PLAYER.TryGetValue(mimeType.ToLowerInvariant(), out playerType))
        return playerType;

	    // 2nd chance: If no mimetype matches, try extension
	    string path = locator.NativeResourcePath.LastPathSegment.Path;
	    string extension = StringUtils.TrimToEmpty(ProviderPathHelper.GetExtension(path)).ToLowerInvariant();

      if (EXTENSIONS2PLAYER.TryGetValue(extension, out playerType))
        return playerType;
      return null;
    }
Ejemplo n.º 44
0
    /// <summary>
    /// Creates an <see cref="IInputSource"/> object for a given mediaitem.
    /// </summary>
    /// <param name="resourceLocator">Locator instance to the media item to create the input source for.</param>
    /// <param name="mimeType">Mime type of the media item, if present. May be <c>null</c>.</param>
    /// <returns>Input source object for the given <paramref name="resourceLocator"/> or <c>null</c>, if no input source
    /// could be created.</returns>
    public IInputSource CreateInputSource(IResourceLocator resourceLocator, string mimeType)
    {
      if (!CanPlay(resourceLocator, mimeType))
        return null;
      IInputSource result;
      _accessor = resourceLocator.CreateAccessor();

      AudioCDResourceAccessor acdra = _accessor as AudioCDResourceAccessor;
      if (acdra != null)
        result = BassCDTrackInputSource.Create(acdra.Drive, acdra.TrackNo);
      else
      {
        string filePath = _accessor.ResourcePathName;
        // Network streams
        INetworkResourceAccessor netra = _accessor as INetworkResourceAccessor;
        if (netra != null)
        {
          result = BassWebStreamInputSource.Create(netra.URL);
        }
        // CDDA
        else if (URLUtils.IsCDDA(filePath))
        {
          ILocalFsResourceAccessor lfra = _accessor as ILocalFsResourceAccessor;
          if (lfra == null)
            return null;
          using (lfra.EnsureLocalFileSystemAccess())
            result = BassFsCDTrackInputSource.Create(lfra.LocalFileSystemPath);
        }
        else
        {
          // Filesystem resources
          IFileSystemResourceAccessor fsra = _accessor as IFileSystemResourceAccessor;
          if (fsra == null)
            return null;
          if (URLUtils.IsMODFile(filePath))
            result = BassMODFileInputSource.Create(fsra);
          else
            result = BassAudioFileInputSource.Create(fsra);
        }
      }
      Log.Debug("InputSourceFactory: Creating input source for media resource '{0}' of type '{1}'", _accessor, result.GetType());
      return result;
    }
Ejemplo n.º 45
0
 /// <summary>
 /// Creates a list finder
 /// </summary>
 /// <param name="resources">The resource locator</param>
 /// <param name="logger">The Logger</param>
 public ListLocator(IResourceLocator resources, ILogger logger)
 {
     this.resources = resources;
     this.logger = logger;
 }
Ejemplo n.º 46
0
    /// <summary>
    /// Sets the data of the new image to be played.
    /// </summary>
    /// <param name="locator">Resource locator of the image item.</param>
    /// <param name="mediaItemTitle">Title of the image item.</param>
    /// <param name="rotation">Rotation of the image.</param>
    /// <param name="flipX">Flipping in horizontal direction.</param>
    /// <param name="flipY">Flipping in vertical direction.</param>
    public void SetMediaItemData(IResourceLocator locator, string mediaItemTitle, RightAngledRotation rotation, bool flipX, bool flipY)
    {
      if (locator == null)
        lock (_syncObj)
        {
          _currentLocator = null;
          return;
        }

      using (IResourceAccessor ra = locator.CreateAccessor())
      {
        IFileSystemResourceAccessor fsra = ra as IFileSystemResourceAccessor;
        if (fsra == null)
          return;
        using (Stream stream = fsra.OpenRead())
        {
          string key = fsra.CanonicalLocalResourcePath.Serialize();
          _texture = ContentManager.Instance.GetTexture(stream, key, true);
          if (_texture == null)
            return;
          if (!_texture.IsAllocated)
            _texture.Allocate();
          if (!_texture.IsAllocated)
            return;
        }
      }
      lock (_syncObj)
      {
        ReloadSettings();
        _state = PlayerState.Active;

        _currentLocator = locator;
        _mediaItemTitle = mediaItemTitle;
        _rotation = rotation;
        _flipX = flipX;
        _flipY = flipY;
        SurfaceDescription desc = _texture.Texture.GetLevelDescription(0);
        _textureMaxUV = new SizeF(_texture.Width / (float) desc.Width, _texture.Height / (float) desc.Height);

        // Reset animation
        _animator.Initialize();

        if (_slideShowTimer != null)
          _slideShowTimer.Change(_slideShowImageDuration, TS_INFINITE);
        else
          CheckTimer();
        _playbackStartTime = DateTime.Now;
        if (_pauseTime.HasValue)
          _pauseTime = _playbackStartTime;
      }
    }
Ejemplo n.º 47
0
    public static bool CanPlay(IResourceLocator locator, string mimeType)
    {
      // First check the mime type
      if (!string.IsNullOrEmpty(mimeType) && !mimeType.StartsWith("image"))
        return false;

      using (IResourceAccessor accessor = locator.CreateAccessor())
      {
        if (!(accessor is IFileSystemResourceAccessor))
          return false;
        string ext = StringUtils.TrimToEmpty(DosPathHelper.GetExtension(accessor.ResourcePathName)).ToLowerInvariant();

        ImagePlayerSettings settings = ServiceRegistration.Get<ISettingsManager>().Load<ImagePlayerSettings>();
        return settings.SupportedExtensions.IndexOf(ext) > -1;
      }
    }
Ejemplo n.º 48
0
 public Formatter SetInitialLocator(IResourceLocator locator)
 {
     _initialLocator = locator;
     return this;
 }
Ejemplo n.º 49
0
 public Formatter Parse()
 {
     var f = _locatorFactory.CloneForTagLib(_lib);
     if (_initialLocator == null)
     {
         _initialLocator = f.GetNewLocator();
     }
     var formatter  = new InternalFormatter(new TagLibParserFactory(new TagLibForParsing(_lib), _expressionLib, f, _tagValidator), _expressionLib, _template, _allowTags, _initialLocator);
     try
     {
         formatter.Parse();
         var templateValidator = _templateValidator ?? CreateTemplateValidatorFor(_lib);
         templateValidator.Validate(formatter.ParsedTemplate);
     }
     finally
     {
         _templateParsed = formatter.ParsedTemplate;
     }
     return this;
 }
Ejemplo n.º 50
0
    public void SetMediaItem(IResourceLocator locator, string mediaItemTitle)
    {
      // free previous opened resource
      FilterGraphTools.TryDispose(ref _resourceAccessor);
      FilterGraphTools.TryDispose(ref _rot);

      _state = PlayerState.Active;
      _isPaused = true;
      try
      {
        _resourceLocator = locator;
        _mediaItemTitle = mediaItemTitle;
        if (_resourceLocator.NativeResourcePath.IsNetworkResource)
        {
          _resourceAccessor = _resourceLocator.CreateAccessor() as INetworkResourceAccessor;
          if (_resourceAccessor == null)
            throw new IllegalCallException("The VideoPlayer can only play network resources of type INetworkResourceAccessor");

          ServiceRegistration.Get<ILogger>().Debug("{0}: Initializing for network media item '{1}'", PlayerTitle, SourcePathOrUrl);
        }
        else
        {
          ILocalFsResourceAccessor lfsr;
          if (!_resourceLocator.TryCreateLocalFsAccessor(out lfsr))
            throw new IllegalCallException("The VideoPlayer can only play local file system resources");

          _resourceAccessor = lfsr;
          ServiceRegistration.Get<ILogger>().Debug("{0}: Initializing for media item '{1}'", PlayerTitle, SourcePathOrUrl);
        }

        // Create a DirectShow FilterGraph
        CreateGraphBuilder();

        // Add it in ROT (Running Object Table) for debug purpose, it allows to view the Graph from outside (i.e. graphedit)
        _rot = new DsROTEntry(_graphBuilder);

        // Add a notification handler (see WndProc)
        _instancePtr = Marshal.AllocCoTaskMem(4);
        IMediaEventEx mee = _graphBuilder as IMediaEventEx;
        if (mee != null)
          mee.SetNotifyWindow(SkinContext.Form.Handle, WM_GRAPHNOTIFY, _instancePtr);

        // Create the Allocator / Presenter object
        AddPresenter();

        ServiceRegistration.Get<ILogger>().Debug("{0}: Adding audio renderer", PlayerTitle);
        AddAudioRenderer();

        ServiceRegistration.Get<ILogger>().Debug("{0}: Adding preferred codecs", PlayerTitle);
        AddPreferredCodecs();

        ServiceRegistration.Get<ILogger>().Debug("{0}: Adding file source", PlayerTitle);
        AddFileSource();

        ServiceRegistration.Get<ILogger>().Debug("{0}: Run graph", PlayerTitle);

        //This needs to be done here before we check if the evr pins are connected
        //since this method gives players the chance to render the last bits of the graph
        OnBeforeGraphRunning();

        // Now run the graph, i.e. the DVD player needs a running graph before getting informations from dvd filter.
        IMediaControl mc = (IMediaControl) _graphBuilder;
        int hr = mc.Run();
        DsError.ThrowExceptionForHR(hr);

        _initialized = true;
        OnGraphRunning();
      }
      catch (Exception)
      {
        Shutdown();
        throw;
      }
    }
Ejemplo n.º 51
0
 public ParsedTemplate ParseNested(ParseHelper helper, IResourceLocator locator)
 {
     try
     {
         helper.PushNewTokenConfiguration(
             true,
             false,
             InternalFormatter.COMMENT,
             InternalFormatter.SEPERATORS,
             null,
             null, //InternalFormatter.LITERALS,
             ResetIndex.LookAhead);
         return new InternalFormatter(new TagLibParserFactoryAdapter(this), _expressionLib, helper, true, true, locator).ParseNested();
     }
     finally
     {
         helper.PopTokenConfiguration(ResetIndex.CurrentAndLookAhead);
     }
 }
Ejemplo n.º 52
0
 /// <summary>
 /// Loads an image from filesystem an returns a new <see cref="FanArtImage"/>.
 /// </summary>
 /// <param name="resourceLocator">Resource to load</param>
 /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param>
 /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param>
 /// <param name="mediaType">MediaType</param>
 /// <param name="fanArtType">FanArtType</param>
 /// <param name="fanArtName">Fanart name</param>
 /// <returns>FanArtImage or <c>null</c>.</returns>
 public static FanArtImage FromResource(IResourceLocator resourceLocator, int maxWidth, int maxHeight, FanArtConstants.FanArtMediaType mediaType, FanArtConstants.FanArtType fanArtType, string fanArtName)
 {
   try
   {
     using (var ra = resourceLocator.CreateAccessor())
     {
       ILocalFsResourceAccessor fsra = ra as ILocalFsResourceAccessor;
       if (fsra != null)
       {
         fsra.PrepareStreamAccess();
         using (var fileStream = fsra.OpenRead())
           // Calling EnsureLocalFileSystemAccess not necessary; only string operation
           return FromStream(fileStream, maxWidth, maxHeight, mediaType, fanArtType, fanArtName, fsra.LocalFileSystemPath);
       }
     }
   }
   catch
   {
   }
   return null;
 }
Ejemplo n.º 53
0
 public IPlayer GetPlayer(IResourceLocator locator, string mimeType)
 {
     if (Enabled && mimeType == "video/bluray")
       {
     BDPlayer player = new BDPlayer();
     try
     {
       player.SetMediaItemLocator(locator);
     }
     catch (Exception)
     {
       LogError("Error playing media item '{0}'", locator);
       player.Dispose();
       return null;
     }
     return player;
       }
       return null;
 }
Ejemplo n.º 54
0
 public void Stop()
 {
   lock (_syncObj)
   {
     if (_state != PlayerState.Active)
       return;
     _state = PlayerState.Stopped;
     _currentLocator = null;
   }
   FireStopped();
 }
Ejemplo n.º 55
0
    /// <summary>
    /// Sets the data of the new image to be played.
    /// </summary>
    /// <param name="locator">Resource locator of the image item.</param>
    /// <param name="mediaItemTitle">Title of the image item.</param>
    /// <param name="rotation">Rotation of the image.</param>
    /// <param name="flipX">Flipping in horizontal direction.</param>
    /// <param name="flipY">Flipping in vertical direction.</param>
    public void SetMediaItemData(IResourceLocator locator, string mediaItemTitle, RightAngledRotation rotation, bool flipX, bool flipY)
    {
      if (locator == null)
        lock (_syncObj)
        {
          DisposeTexture();
          _currentLocator = null;
          return;
        }

      Texture texture;
      ImageInformation imageInformation;
      using (IResourceAccessor ra = locator.CreateAccessor())
      using (Stream stream = ra.OpenRead())
        texture = Texture.FromStream(SkinContext.Device, stream, (int) stream.Length, 0, 0, 1, Usage.None,
            Format.A8R8G8B8, Pool.Default, Filter.None, Filter.None, 0, out imageInformation);
      lock (_syncObj)
      {
        ReloadSettings();
        _state = PlayerState.Active;

        DisposeTexture();
        _currentLocator = locator;
        _mediaItemTitle = mediaItemTitle;
        _texture = texture;
        _rotation = rotation;
        _flipX = flipX;
        _flipY = flipY;
        SurfaceDescription desc = _texture.GetLevelDescription(0);
        _textureMaxUV = new SizeF(imageInformation.Width / (float) desc.Width, imageInformation.Height / (float) desc.Height);

        // Reset animation
        _animator.Initialize();

        if (_slideShowTimer != null)
          _slideShowTimer.Change(_slideShowImageDuration, TS_INFINITE);
        else
          CheckTimer();
        _playbackStartTime = DateTime.Now;
        if (_pauseTime.HasValue)
          _pauseTime = _playbackStartTime;
      }
    }
Ejemplo n.º 56
0
    public void SetMediaItem(IResourceLocator locator, string mediaItemTitle)
    {
      // free previous opened resource
      FilterGraphTools.TryDispose(ref _resourceAccessor);
      FilterGraphTools.TryDispose(ref _rot);

      _state = PlayerState.Active;
      _isPaused = true;
      try
      {
        _resourceLocator = locator;
        _mediaItemTitle = mediaItemTitle;
        CreateResourceAccessor();

        // Create a DirectShow FilterGraph
        CreateGraphBuilder();

        // Add it in ROT (Running Object Table) for debug purpose, it allows to view the Graph from outside (i.e. graphedit)
        _rot = new DsROTEntry(_graphBuilder);

        // Add a notification handler (see WndProc)
        _instancePtr = Marshal.AllocCoTaskMem(4);
        IMediaEventEx mee = _graphBuilder as IMediaEventEx;
        if (mee != null)
          mee.SetNotifyWindow(SkinContext.Form.Handle, WM_GRAPHNOTIFY, _instancePtr);

        // Create the Allocator / Presenter object
        AddPresenter();

        ServiceRegistration.Get<ILogger>().Debug("{0}: Adding audio renderer", PlayerTitle);
        AddAudioRenderer();

        ServiceRegistration.Get<ILogger>().Debug("{0}: Adding preferred codecs", PlayerTitle);
        AddPreferredCodecs();

        ServiceRegistration.Get<ILogger>().Debug("{0}: Adding source filter", PlayerTitle);
        AddSourceFilter();

        ServiceRegistration.Get<ILogger>().Debug("{0}: Run graph", PlayerTitle);

        //This needs to be done here before we check if the evr pins are connected
        //since this method gives players the chance to render the last bits of the graph
        OnBeforeGraphRunning();

        // Now run the graph, i.e. the DVD player needs a running graph before getting informations from dvd filter.
        IMediaControl mc = (IMediaControl) _graphBuilder;
        int hr = mc.Run();
        new HRESULT(hr).Throw();

        _initialized = true;
        OnGraphRunning();
      }
      catch (Exception)
      {
        Shutdown();
        throw;
      }
    }
Ejemplo n.º 57
0
 /// <summary>
 /// Creates a list helper
 /// </summary>
 /// <param name="contentTypeBuilder">A content type helper</param>
 public ListHelper(ContentTypeBuilder contentTypeBuilder, IResourceLocator resourceLocator)
 {
     this.contentTypeBuilder = contentTypeBuilder;
     this.resourceLocator = resourceLocator;
 }
Ejemplo n.º 58
0
 public static Formatter LocatorBasedFormatter(ITagLib lib, string path, IResourceLocator locator, IResourceLocatorFactory factory)
 {
     var template = locator.GetDataAsString(path);
     return new Formatter(template).
                 OverrideLib(lib).
                 OverrideExpressionLib(factory.ExpressionLib).
                 AllowTags(true).
                 SetLocatorFactory(factory).
                 SetInitialLocator(locator.Update(path)).
                 SetTagValidator(CreateTagValidatorFor(lib)).
                 Parse();
 }
Ejemplo n.º 59
0
    public static bool CanPlay(IResourceLocator locator, string mimeType)
    {
      // First check the Mime Type
      if (!string.IsNullOrEmpty(mimeType) && !mimeType.StartsWith("audio"))
        return false;

      using (IResourceAccessor accessor = locator.CreateAccessor())
      {
        if (accessor is AudioCDResourceAccessor || accessor is INetworkResourceAccessor)
          return true;
        string ext = DosPathHelper.GetExtension(accessor.ResourcePathName).ToLowerInvariant();
        BassPlayerSettings settings = ServiceRegistration.Get<ISettingsManager>().Load<BassPlayerSettings>();
        return settings.SupportedExtensions.IndexOf(ext) > -1;
      }
    }
Ejemplo n.º 60
0
 /// <summary>
 /// Initializes a new <see cref="FieldChemaHelper"/> instance
 /// </summary>
 /// <param name="resourceLocator">The resource locator</param>
 /// <param name="logger">The logging utility</param>
 /// <param name="fieldLocator">Field finder</param>
 public FieldSchemaHelper(IResourceLocator resourceLocator, ILogger logger, IFieldLocator fieldLocator)
 {
     this.resourceLocator = resourceLocator;
     this.logger = logger;
     this.fieldLocator = fieldLocator;
 }