예제 #1
0
        public bool Play(MediaItem mediaItem, StartTime startTime)
        {
            IPlayer player = null;

            try
            {
                IReusablePlayer rp;
                lock (SyncObj)
                {
                    CheckActive();
                    player = _player;
                    rp     = _player as IReusablePlayer;
                }
                if (rp != null)
                {
                    if (rp.NextItem(mediaItem, startTime))
                    {
                        OnPlayerStarted(rp);
                        return(true);
                    }
                }
                ReleasePlayer_NoLock();
                ICollection <Exception> exceptions;
                player = _playerManager.BuildPlayer_NoLock(mediaItem, out exceptions);
                if (player == null)
                {
                    HandleUnableToPlay(mediaItem, exceptions);
                }
                else
                {
                    IMediaPlaybackControl mpc;
                    IDisposable           disposePlayer = null;
                    lock (SyncObj)
                    {
                        if (_player != null)
                        {
                            disposePlayer = _player as IDisposable; // If we got a race condition between the locks
                        }
                        _player = player;
                        mpc     = player as IMediaPlaybackControl;
                    }
                    RegisterPlayerEvents_NoLock(player);
                    CheckAudio_NoLock();
                    if (disposePlayer != null)
                    {
                        disposePlayer.Dispose();
                    }
                    OnPlayerStarted(player);
                    if (mpc != null)
                    {
                        mpc.Resume();
                    }
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Warn("PlayerSlotController: Error playing '{0}'", e, mediaItem);
                IDisposable disposePlayer = player as IDisposable;
                if (disposePlayer != null)
                {
                    disposePlayer.Dispose();
                }
                return(false);
            }
        }
예제 #2
0
        public bool Play(MediaItem mediaItem, StartTime startTime)
        {
            IPlayer player = null;

            try
            {
                IReusablePlayer rp;
                lock (SyncObj)
                {
                    CheckActive();
                    player = _player;
                    rp     = _player as IReusablePlayer;
                }
                if (rp != null)
                {
                    if (rp.NextItem(mediaItem, startTime))
                    {
                        OnPlayerStarted(rp);
                        return(true);
                    }
                }
                ReleasePlayer_NoLock();
                ICollection <Exception> exceptions;
                player = _playerManager.BuildPlayer_NoLock(mediaItem, out exceptions);
                if (player == null)
                {
                    if (mediaItem.IsStub || mediaItem.IsVirtual) //No player found for stub or virtual item which is expected
                    {
                        Close_NoLock();
                        return(false);
                    }

                    HandleUnableToPlay(mediaItem, exceptions);
                    OnPlaybackError(null);
                }
                else
                {
                    IMediaPlaybackControl mpc;
                    IDisposable           disposePlayer = null;
                    lock (SyncObj)
                    {
                        if (_player != null)
                        {
                            disposePlayer = _player as IDisposable; // If we got a race condition between the locks
                        }
                        _player = player;
                        mpc     = player as IMediaPlaybackControl;
                    }
                    RegisterPlayerEvents_NoLock(player);
                    CheckAudio_NoLock();
                    if (disposePlayer != null)
                    {
                        disposePlayer.Dispose();
                    }
                    OnPlayerStarted(player);

                    // Handling of resume info.
                    object resumeObject;
                    if (ContextVariables.TryGetValue(PlayerContext.KEY_RESUME_STATE, out resumeObject))
                    {
                        IResumeState     resumeState     = (IResumeState)resumeObject;
                        IResumablePlayer resumablePlayer = player as IResumablePlayer;
                        if (resumablePlayer != null)
                        {
                            resumablePlayer.SetResumeState(resumeState);
                        }
                    }

                    if (mpc != null)
                    {
                        mpc.Resume();
                    }
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Warn("PlayerSlotController: Error playing '{0}'", e, mediaItem);
                IDisposable disposePlayer = player as IDisposable;
                if (disposePlayer != null)
                {
                    disposePlayer.Dispose();
                }
                return(false);
            }
        }