Ejemplo n.º 1
0
        private async void Client_PlayCommand(object sender, MediaBrowser.Model.Events.GenericEventArgs <PlayRequest> e)
        {
            try
            {
                log.Debug("Play command received.");
                if (playingItem != null)
                {
                    log.InfoFormat("{0} is already playing, stopping player.", playingItem.Name);
                    StopPlayer();
                }

                var playReq   = e.Argument;
                var playingId = playReq.ItemIds[0]; //only playing 1 item is currently supported
                playingItem = await client.GetItemAsync(playingId, playReq.ControllingUserId);

                log.InfoFormat("Playing \"{0}\" from \"{1}\"", playingItem.Name, playingItem.Path);
                if (player.Play(playingItem.Path, playingItem.UserData.PlaybackPositionTicks))
                {
                    log.Debug("Playback started.");
                    client.ReportPlaybackStartAsync(new PlaybackStartInfo
                    {
                        CanSeek    = true,
                        ItemId     = playingId,
                        PlayMethod = PlayMethod.DirectPlay
                    }).GetAwaiter().GetResult();

                    progressReporter = new ProgressReporter(client, player, 1000, playingId);
                    progressReporter.PlayerStopped += ProgressReporter_PlayerStopped;
                    progressReporter.Start();
                    log.Debug("ProgressReporter started.");
                }
                else
                {
                    log.Error("Player failed to start.");
                }
            }
            catch (Exception ex)
            {
                log.Error("Play command failed.", ex);
            }
        }
Ejemplo n.º 2
0
 private void ResetPlayingItem()
 {
     playingItem = null;
     progressReporter.PlayerStopped -= ProgressReporter_PlayerStopped;
     progressReporter = null; //will terminate on its own along with the player
 }