/// <summary>
 /// Handle the Play/Pause button being triggered
 /// </summary>
 /// <param name="shouldPlay">Should the service play or pause</param>
 private void PlayPause(bool shouldPlay)
 {
     if (!shouldPlay && MLMusicService.PlaybackState == MLMusicServicePlaybackState.Playing)
     {
         MLMusicService.PausePlayback();
     }
     else if (shouldPlay && MLMusicService.PlaybackState != MLMusicServicePlaybackState.Playing)
     {
         MLMusicService.ResumePlayback();
     }
 }
 private void OnApplicationPause(bool pause)
 {
     if (MLMusicService.IsStarted)
     {
         MLResult result = pause ? MLMusicService.PausePlayback() : MLMusicService.ResumePlayback();
         if (!result.IsOk)
         {
             Debug.LogErrorFormat("MusicServiceExample failed to {0} the current track, disabling script. Reason: {1}.", pause ? "pause" : "resume", result);
             enabled = false;
             return;
         }
     }
 }
        private void OnApplicationPause(bool pause)
        {
            if (MLMusicService.IsStarted)
            {
                MLResult result = pause ? MLMusicService.PausePlayback() : MLMusicService.ResumePlayback();
                if (!result.IsOk)
                {
                    if (result.Code == MLResultCode.PrivilegeDenied)
                    {
                        Instantiate(Resources.Load("PrivilegeDeniedError"));
                    }

                    Debug.LogErrorFormat("MusicServiceExample failed to {0} the current track, disabling script. Reason: {1}.", pause ? "pause" : "resume", result);
                    enabled = false;
                    return;
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Pauses, resumes or starts playback based on playback state.
        /// </summary>
        public void PlayPause()
        {
            #if PLATFORM_LUMIN
            MLResult result;

            switch (MLMusicService.PlaybackState)
            {
            case MLMusicService.PlaybackStateType.Playing:
                result = MLMusicService.PausePlayback();
                if (!result.IsOk)
                {
                    Debug.LogErrorFormat("MLMusicServiceBehavior failed to pause the current track, disabling script. Reason: {0}.", result);
                    enabled = false;
                    return;
                }
                break;

            case MLMusicService.PlaybackStateType.Paused:
                result = MLMusicService.ResumePlayback();
                if (!result.IsOk)
                {
                    Debug.LogErrorFormat("MLMusicServiceBehavior failed to resume the current track, disabling script. Reason: {0}.", result);
                    enabled = false;
                    return;
                }
                break;

            case MLMusicService.PlaybackStateType.Stopped:
                result = MLMusicService.StartPlayback();
                if (!result.IsOk)
                {
                    Debug.LogErrorFormat("MLMusicServiceBehavior failed to start the current track, disabling script. Reason: {0}.", result);
                    enabled = false;
                    return;
                }
                break;

            default:
                break;
            }
            #endif
        }
        /// <summary>
        /// Handle the Play/Pause button being triggered
        /// </summary>
        private void PlayPause()
        {
            switch (MLMusicService.PlaybackState)
            {
            case MLMusicServicePlaybackState.Playing:
                MLMusicService.PausePlayback();
                break;

            case MLMusicServicePlaybackState.Paused:
                MLMusicService.ResumePlayback();
                break;

            case MLMusicServicePlaybackState.Stopped:
                MLMusicService.StartPlayback();
                break;

            default:
                break;
            }
        }
Exemple #6
0
        /// <summary>
        /// Pauses or resumes playback based on if app is or was playing when paused.
        /// </summary>
        /// <param name="pause">Determines if it's a pause or a resume.</param>
        private void OnApplicationPause(bool pause)
        {
            #if PLATFORM_LUMIN
            if (MLMusicService.IsStarted)
            {
                if (pause)
                {
                    playbackStateOnPause = PlaybackState;
                }

                if (playbackStateOnPause == MLMusicService.PlaybackStateType.Playing)
                {
                    MLResult result = pause ? MLMusicService.PausePlayback() : MLMusicService.ResumePlayback();
                    if (!result.IsOk)
                    {
                        Debug.LogErrorFormat("MLMusicServiceBehavior failed to {0} the current track, disabling script. Reason: {1}.", pause ? "pause" : "resume", result);
                        enabled = false;
                        return;
                    }
                }
            }
            #endif
        }