示例#1
0
 /// <summary>
 /// Seek to the specified position in the current track.
 /// </summary>
 /// <param name="targetMS">The target value to seek to.</param>
 public void Seek(uint targetMS)
 {
     #if PLATFORM_LUMIN
     MLResult result = MLMusicService.Seek(targetMS);
     if (!result.IsOk)
     {
         Debug.LogErrorFormat("MLMusicServiceBehavior failed to seek in the current track, disabling script. Reason: {0}.", result);
         enabled = false;
         return;
     }
     #endif
 }
        /// <summary>
        /// Handle the seek bar being moved to a new position
        /// </summary>
        /// <param name="sliderValue">The new value of the seek bar in range [0, 1]</param>
        private void Seek(float sliderValue)
        {
            uint targetMS = (uint)(_trackLengthMS * sliderValue);

            float currentValue = _trackHeadPositionMS / (float)_trackLengthMS;

            if (Math.Abs(currentValue - sliderValue) < SEEK_EPSILON)
            {
                return;
            }

            MLMusicService.Seek(targetMS);
        }
        /// <summary>
        /// Handle the seek bar being moved to a new position
        /// </summary>
        /// <param name="sliderValue">The new value of the seek bar in range [0, 1]</param>
        private void Seek(float sliderValue)
        {
            uint lengthMS = MLMusicService.TrackLength * 1000;
            uint targetMS = (uint)(lengthMS * sliderValue);

            uint  current      = MLMusicService.CurrentPosition;
            float currentValue = (float)current / (float)lengthMS;

            if (Math.Abs(currentValue - sliderValue) < SEEK_EPSILON)
            {
                return;
            }

            MLMusicService.Seek(targetMS);
        }