Ejemplo n.º 1
0
    // Checks whether the audio and video file formats of the song are supported.
    // Returns true iff the audio file of the SongMeta exists and is supported.
    private bool CheckSupportedMediaFormats(SongMeta songMeta)
    {
        // Check video format.
        // Video is optional.
        if (!songMeta.Video.IsNullOrEmpty())
        {
            if (!ApplicationUtils.IsSupportedVideoFormat(Path.GetExtension(songMeta.Video)))
            {
                Debug.LogWarning("Unsupported video format: " + songMeta.Video);
                songMeta.Video = "";
            }
            else if (!File.Exists(SongMetaUtils.GetAbsoluteSongVideoPath(songMeta)))
            {
                Debug.LogWarning("Video file does not exist: " + SongMetaUtils.GetAbsoluteSongVideoPath(songMeta));
                songMeta.Video = "";
            }
        }

        // Check audio format.
        // Audio is mandatory. Without working audio file, the song cannot be played.
        if (!ApplicationUtils.IsSupportedAudioFormat(Path.GetExtension(songMeta.Mp3)))
        {
            Debug.LogWarning("Unsupported audio format: " + songMeta.Mp3);
            return(false);
        }
        else if (!File.Exists(SongMetaUtils.GetAbsoluteSongFilePath(songMeta)))
        {
            Debug.LogWarning("Audio file does not exist: " + SongMetaUtils.GetAbsoluteSongFilePath(songMeta));
            return(false);
        }

        return(true);
    }
Ejemplo n.º 2
0
    public void Init(SongMeta songMeta)
    {
        this.SongMeta = songMeta;

        string    songPath  = SongMetaUtils.GetAbsoluteSongFilePath(songMeta);
        AudioClip audioClip = AudioManager.Instance.GetAudioClip(songPath);

        if (audioClip != null)
        {
            audioPlayer.clip       = audioClip;
            DurationOfSongInMillis = 1000.0 * audioClip.samples / audioClip.frequency;
        }
        else
        {
            DurationOfSongInMillis = 0;
        }
    }
    public void CheckAudioAndStartSingScene()
    {
        if (SelectedSong != null)
        {
            // Check that the audio file exists
            string audioPath = SongMetaUtils.GetAbsoluteSongFilePath(SelectedSong);
            if (!File.Exists(audioPath))
            {
                UiManager.Instance.CreateWarningDialog("Audio Error", "Audio file does not exist: " + audioPath);
                return;
            }

            // Check that the used audio format can be loaded.
            songAudioPlayer.Init(SelectedSong);
            if (!songAudioPlayer.HasAudioClip)
            {
                UiManager.Instance.CreateWarningDialog("Audio Error", "Audio file could not be loaded.\nPlease use a supported format.");
                return;
            }

            StartSingScene(SelectedSong);
        }
    }
Ejemplo n.º 4
0
    void Update()
    {
        // Automatically stop playback after a given threshold (e.g. only play the selected notes)
        if (songAudioPlayer.IsPlaying &&
            StopPlaybackAfterPositionInSongInMillis > 0 &&
            songAudioPlayer.PositionInSongInMillis > StopPlaybackAfterPositionInSongInMillis)
        {
            songAudioPlayer.PauseAudio();
            StopPlaybackAfterPositionInSongInMillis = 0;
        }

        // Create the audio waveform image if not done yet.
        if (!audioWaveFormInitialized && songAudioPlayer.HasAudioClip && songAudioPlayer.AudioClip.samples > 0)
        {
            using (new DisposableStopwatch($"Created audio waveform in <millis> ms"))
            {
                // For drawing the waveform, the AudioClip must not be streamed. All data must have been fully loaded.
                AudioClip audioClip = AudioManager.Instance.GetAudioClip(SongMetaUtils.GetAbsoluteSongFilePath(SongMeta), false);
                audioWaveFormInitialized = true;
                audioWaveFormVisualizer.DrawWaveFormMinAndMaxValues(audioClip);
            }
        }
    }