コード例 #1
0
        /// <summary>
        /// Creates playlists from songs.
        /// </summary>
        /// <param name="json"></param>
        public void CreateCatalogue(string json)
        {
            var N             = SimpleJSON.JSON.Parse(json);
            var playlistCount = N["catalog"].Count;

            for (int i = 0; i < playlistCount; i++)
            {
                VPlaylist playlist = new VPlaylist(N["catalog"][i]["id"].AsInt, N["catalog"][i]["title"].Value);
                AddPlaylist(playlist);

                var songsCount = N["catalog"][i]["songs"].Count;
                for (int j = 0; j < songsCount; j++)
                {
                    playlist.AddSong(new VSong
                    {
                        Id       = N["catalog"][i]["songs"][j]["id"].Value,
                        Title    = N["catalog"][i]["songs"][j]["title"].Value,
                        Artist   = N["catalog"][i]["songs"][j]["artist"].Value,
                        Site     = string.IsNullOrEmpty(N["catalog"][i]["songs"][j]["site"].Value) ? "http://www.apollomusic.dk/game-music" : N["catalog"][i]["songs"][j]["site"].Value,
                        Album    = N["catalog"][i]["songs"][j]["album"].Value,
                        Duration = N["catalog"][i]["songs"][j]["duration"].Value,
                        Playlist = playlist.Id
                    });
                }
                playlist.RandomizeSongOrder();
            }

            VPlayerController.Instance.CatalogueReady();
        }
コード例 #2
0
        private void AddPlaylist(VPlaylist playlist)
        {
            if (m_playlists.Contains(playlist))
            {
                return;
            }

            m_playlists.Add(playlist);
        }
コード例 #3
0
        /// <summary>
        /// Load playlist from Player Prefs. NOTE: Playlist order may change in backend so this might not be accurate.
        /// </summary>
        private void LoadLastPlayedPlaylist()
        {
            int id = PlayerPrefs.GetInt(VStrings.LAST_PLAYED);

            foreach (VPlaylist v in m_catalogue.GetAllPlaylists())
            {
                if (v.Id == id)
                {
                    m_currentPlaylist = v;
                    return;
                }
            }

            // If not found, get first
            m_currentPlaylist = m_catalogue.GetPlaylistByIndex(0);
        }
コード例 #4
0
        /// <summary>
        /// Start playing the selected playlist.
        /// </summary>
        /// <param name="playlist"></param>
        public void Play(VPlaylist playlist)
        {
            m_currentPlaylist = playlist;

            Play();
        }
コード例 #5
0
        /// <summary>
        /// Handle play logic
        /// </summary>
        public void Play()
        {
            // If player is in error state, try to authorize the player again
            if (m_currentState.IsError)
            {
                TryRelogin();
                return;
            }

            // No network connection, retryable error
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                ShowErrorInUI(VStrings.InternetConnectionError, true);
                return;
            }

            if (!m_playerSessionActive)
            {
                m_playerSessionStartTime = Time.realtimeSinceStartup;
                m_playerSessionActive    = true;
            }

            // Save the playlist
            if (m_currentPlaylist != null)
            {
                SaveLastPlayedPlaylist(m_currentPlaylist);
            }

            // If there are no catalogue or playlists, show error. Retryable.
            if (m_catalogue == null || m_catalogue.GetAllPlaylists().Count <= 0)
            {
                ShowErrorInUI(VStrings.ErrorPlaylists, true);
                return;
            }


            if (m_currentState.IsPaused &&
                m_currentSong != null &&
                m_currentSong.Playlist == m_currentPlaylist.Id)
            {
                // There was a song playing, resume playback
                m_musicPlayback.Resume();
            }
            else
            {
                // Get new song or get an ad

                // If pre roll ad is not played yet or if ad should be played next
                if (!VSettings.IsPreRollAdPlayed || m_playAdNext)
                {
                    RemoveMusicPlaybackListeners();
                    AddAdPlaybackListeners();

                    m_currentSong = null;

                    StartAdPlayback();
                    return;
                }

                // No playlist specified (play pressed when player is in stand-by)
                if (m_currentPlaylist == null)
                {
                    if (m_catalogue.GetAllPlaylists().Count > 0)
                    {
                        m_currentPlaylist = m_catalogue.GetPlaylistByIndex(0);
                    }
                    else
                    {
                        // Should not go here but handling error just in case
                        ShowErrorInUI(VStrings.ErrorPlaylists, true);
                        return;
                    }
                }

                // Get next song and start playback
                m_currentSong = m_currentPlaylist.GetNextSong();
                m_musicPlayback.Play(m_currentSong);

                // Keep track on played songs to get ads played between songs
                m_songCounter++;
                // If ad frequency is not set, it won't go here at all = mid roll ads are not played
                if (m_songCounter >= VSettings.AdFrequency && VSettings.AdFrequency > 0)
                {
                    m_playAdNext = true;
                }
            }
        }
コード例 #6
0
 /// <summary>
 /// Save user's playlist selection to Player Prefs.
 /// </summary>
 /// <param name="playlist"></param>
 private void SaveLastPlayedPlaylist(VPlaylist playlist)
 {
     PlayerPrefs.SetInt(VStrings.LAST_PLAYED, playlist.Id);
 }
コード例 #7
0
 public void SetInfo(VPlaylist playlist)
 {
     AssignedPlaylist  = playlist;
     PlaylistName.text = AssignedPlaylist.Name;
     gameObject.name   = AssignedPlaylist.Name;
 }