Example #1
0
        void CheckPlaybackStatus(NSTimer timer)
        {
            try
            {
                if (CurrentSong == null || (!(player.CurrentPlayer?.IsPlayerItemValid ?? false) && (DateTime.Now - playbackStarted).TotalSeconds < 10))
                {
                    return;
                }
                if (Duration > 0 && lastDurration.IsZero())
                {
                    Seek(Settings.CurrentPlaybackPercent);
                    lastDurration = Duration;
                }
                if (State == PlaybackState.Paused || State == PlaybackState.Stopped)
                {
                    return;
                }
                var time = player.CurrentTimeSeconds();
                if (player.Rate > 0 && (time - lastSeconds).IsNotZero())
                {
                    lastSeconds = time;
                    return;
                }
                if (checkPlaybackTask != null && !checkPlaybackTask.IsCompleted)
                {
                    return;
                }
                checkPlaybackTask = Task.Run(async() =>
                {
                    //if (player.Rate > 0)
                    //{
                    await PrepareSong(CurrentSong, isVideo);
                    await player.PlaySong(CurrentSong, isVideo, true);
                    if (time > 0)
                    {
                        player.Seek(time);
                    }

                    //}
                    //else
                    //Play();
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Example #2
0
        void CheckPlaybackStatus(NSTimer timer)
        {
            if (CurrentSong == null || CurrentItem == null)
            {
                return;
            }
            if (Duration > 0 && Math.Abs(lastDurration) < Double.Epsilon)
            {
                Seek(Settings.CurrentPlaybackPercent);
                lastDurration = Duration;
            }
            if (State == PlaybackState.Paused || State == PlaybackState.Stopped)
            {
                return;
            }
            var time = player.CurrentTimeSeconds();

            if (player.Rate > 0 && Math.Abs(time - lastSeconds) > Double.Epsilon)
            {
                lastSeconds = time;
                return;
            }
            if (checkPlaybackTask != null && !checkPlaybackTask.IsCompleted)
            {
                return;
            }
            checkPlaybackTask = Task.Run(async() => {
                if (player.Rate > 0)
                {
                    await PrepareSong(CurrentSong, isVideo);
                    await player.PlaySong(CurrentSong, isVideo, true);
                    if (time > 0)
                    {
                        player.Seek(time);
                    }
                }
                else
                {
                    Play();
                }
            });
        }