/// <summary> /// Get song from player controller, prepare and play it. /// </summary> /// <param name="song"></param> public void Play(VSong song) { StopPlayback(); m_currentSong = song; StartCoroutine(PrepareSong()); }
public void AddSong(VSong song) { if (m_songs == null) { m_songs = new List <VSong>(); } if (!m_songs.Contains(song)) { m_songs.Add(song); } }
public VSong GetNextSong() { if (m_currentSong >= m_songs.Count) { m_currentSong = 0; } VSong song = m_songs[m_currentSong]; m_currentSong++; return(song); }
public void SendSongState(VSong song, bool wasSkipped) { if (song == null) { return; } ASongInfo songInfo = new ASongInfo() { song_id = int.Parse(song.Id), genre_id = song.Playlist, state = (wasSkipped) ? 0 : 1 }; string postData = JsonUtility.ToJson(songInfo); m_network.CallPost(VStrings.ANALYTICS_PLAYBACK, postData, null); }
/// <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; } } }