예제 #1
0
        /// <summary>
        /// Transitions from one music configuration to another, using the specified transition.
        ///
        /// MusicStack elements that share the same <see cref="IMusicAsset"/> can reuse the existing audio player
        /// when transitioning between them. This lets the music keep going.
        /// </summary>
        private void TransitionToMusic(IMusicStackElement oldElement, IMusicStackElement newElement, Transition transition)
        {
            // We get the music data associated with each stack element.
            var oldMusicData = GetAudioData(oldElement);
            var newMusicData = GetAudioData(newElement);

            if (oldMusicData != null)
            {
                playerControllers[oldMusicData.GetMusicID()].StopMusic(transition.fadeOutTime);
            }

            if (newMusicData != null)
            {
                var id = newMusicData.GetMusicID();
                if (playerControllers.ContainsKey(id))
                {
                    // Reuse an existing player if one exists.
                    playerControllers[id].StartMusic(transition.fadeInTime, transition.fadeInDelay, newElement.GetDesiredVolume());
                }
                else
                {
                    // Create a new player
                    var player = newMusicData.CreatePlayer();
                    player.outputAudioMixerGroup = mixerGroup;
                    var controller = new MusicPlayerController(player);
                    playerControllers.Add(id, controller);
                    controller.StartMusic(transition.fadeInTime, transition.fadeInDelay, newElement.GetDesiredVolume());
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Used to select a media file at a given index value within the current playlist
        /// </summary>
        /// <param name="index">The playlist index of the media file to select as an integer</param>
        /// <param name="overrideRepeat">True overrides repeat setting to select a new song, default is false</param>
        public void ChangeMusicSelection(int index)
        {
            if (SelectedMediaIndex != index)
            {
                SelectedMediaIndex = index;

                MusicPlayerController.SelectPlaylistItem(SelectedMediaIndex);
                UpdateMusicPlayer();
            }
        }
예제 #3
0
 // Start is called before the first frame update
 void Awake()
 {
     timerStart  = Time.time;
     instance    = this;
     audioSource = GetComponent <AudioSource>();
     SetSongName();
     timeSong            = transform.Find("txtTime").GetComponent <Text>();
     nameSong            = transform.Find("txtSong").GetComponent <Text>();
     nameSong.text       = audioSource.clip.name;
     sliderTime          = transform.Find("sliderTime").GetComponent <Slider>();
     sliderTime.maxValue = audioSource.clip.length;
 }
 // Use this for initialization
 void Start()
 {
     if (instance != null)
     {
         Destroy(gameObject);
     }
     else
     {
         instance = this;
         GameObject.DontDestroyOnLoad(gameObject);
     }
 }
예제 #5
0
 void Awake()
 {
     if (instance)
     {
         Destroy(gameObject);
     }
     else
     {
         instance = this;
         GameObject.DontDestroyOnLoad(gameObject);
     }
 }
예제 #6
0
        private async Task <bool> GetMediaFiles()
        {
            var fileList = await KnownFolders.MusicLibrary.GetFilesAsync();

            foreach (var file in fileList.Where(x => x.ContentType.Contains("audio")))
            {
                // Add to collection for displaying list of media file sources
                MediaFileCollection.Add(file);

                // Add source to the media player's playlist
                var source = MediaSource.CreateFromStream(await file.OpenAsync(Windows.Storage.FileAccessMode.Read), file.ContentType);
                MusicPlayerController.AddToPlaylist(source);
            }
            return(true);
        }
예제 #7
0
 private void Start()
 {
     if (instance != null && instance != this)
     {
         Destroy(gameObject);
         print("Duplicate Music Player: Self Destructing!");
     }
     else
     {
         instance = this;
         GameObject.DontDestroyOnLoad(gameObject);
         music      = GetComponent <AudioSource>();
         music.clip = startClip;
         music.loop = true;
         music.Play();
     }
 }
예제 #8
0
 public void OnActivated(MusicPlayerServer mediaPlayer)
 {
     _musicPlayerController = new MusicPlayerController(mediaPlayer);
 }