Пример #1
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);
        }
Пример #2
0
        /// <summary>
        /// Enqueues a play workitem for the given mediaitem.
        /// </summary>
        /// <param name="locator">Resource locator of the to-be-played item.</param>
        /// <param name="mimeType">Mime type of the media item to be played, if given. May be <c>null</c>.</param>
        /// <param name="mediaItemTitle">Title of the media item to be played.</param>
        /// <remarks>
        /// The workitem will actually be executed on the controller's mainthread.
        /// </remarks>
        public void SetMediaItemLocator(IResourceLocator locator, string mimeType, string mediaItemTitle)
        {
            if (_externalState != PlayerState.Stopped)
            {
                Stop();
            }
            IInputSource inputSource = _inputSourceFactory.CreateInputSource(locator, mimeType);

            if (inputSource == null)
            {
                ServiceRegistration.Get <ILogger>().Warn("Unable to play '{0}'", locator);
                return;
            }
            _mediaItemTitle = mediaItemTitle;
            _externalState  = PlayerState.Active;
            _controller.MoveToNextItem_Async(inputSource, StartTime.AtOnce);
        }