async void OnAlbumItemClicked(object sender, AdapterView.ItemClickEventArgs e) { var selectedEpisode = _album.Episodes [e.Position]; if (AndroidAudioDownloader.ViewsDownloadInProgressByAudioId.ContainsKey(selectedEpisode.RemoteUrl)) { return; } if (AudioDownloader.HasLocalFile(selectedEpisode.RemoteUrl, selectedEpisode.FileSize)) { var resultIntent = new Intent(); ExtraUtils.PutEpisode(resultIntent, selectedEpisode.Id); ExtraUtils.PutAlbum(resultIntent, _album.Id); ExtraUtils.PutSelectedTab(resultIntent, (int)MainActivity.TabTitle.Player); SetResult(Result.Ok, resultIntent); StartService(PlayerService.CreateIntent( this, PlayerService.ACTION_PLAY, _album.Id, selectedEpisode.Id )); Finish(); } else { await AndroidAudioDownloader.StartDownloadAsync(e.Position, selectedEpisode.RemoteUrl, ListView); } }
public override View GetView(int position, View convertView, ViewGroup parent) { var episode = _album.Episodes[position]; View iconAndTitleView; if (AndroidAudioDownloader.ViewsDownloadInProgressByAudioId.ContainsKey(episode.RemoteUrl)) { iconAndTitleView = AndroidAudioDownloader.ViewsDownloadInProgressByAudioId [episode.RemoteUrl]; } else { iconAndTitleView = base.GetView(position, convertView, parent); iconAndTitleView.SetNarratorsAndAuthors(episode.Authors == null ? (IManMadeItem)episode : _album); var downloadProgressBar = iconAndTitleView.FindViewById <ProgressBar> (Resource.Id.DownloadProgress); downloadProgressBar.Progress = AudioDownloader.HasLocalFile(episode.RemoteUrl, episode.FileSize) ? downloadProgressBar.Max : 0; } if (episode == DrunkAudibleApplication.Self.CurrentEpisode) { var isPlayingIndicator = iconAndTitleView.FindViewById <TextView> (Resource.Id.IsPlayingIndicator); IconProvider.ConvertTextViewToIcon(Context.Assets, isPlayingIndicator); isPlayingIndicator.Visibility = ViewStates.Visible; } return(iconAndTitleView); }
async void Play() { if (_paused && _player != null) { _paused = false; //We are simply paused so just start again _player.Start(); StartForeground(); return; } if (_player == null) { IntializePlayer(); } if (_player.IsPlaying) { return; } try { if (CurrentEpisode == null || Math.Abs(CurrentEpisode.Duration - CurrentEpisode.CurrentTime) < COMPARISON_EPSILON || !AudioDownloader.HasLocalFile(CurrentEpisode.RemoteUrl, CurrentEpisode.FileSize)) { return; } var file = new Java.IO.File(AudioDownloader.GetFilePath(CurrentEpisode.RemoteUrl)); var fis = new Java.IO.FileInputStream(file); // TODO reorganize it to play selected audio. // await player.SetDataSourceAsync(ApplicationContext, Net.Uri.Parse(Mp3 await _player.SetDataSourceAsync(fis.FD); var focusResult = _audioManager.RequestAudioFocus(this, Stream.Music, AudioFocus.Gain); if (focusResult != AudioFocusRequest.Granted) { Log.Debug(DEBUG_TAG, "Could not get audio focus"); } _player.Prepare(); CurrentPosition = (int)CurrentEpisode.CurrentTime; AquireWifiLock(); StartForeground(); } catch (Exception ex) { Log.Debug(DEBUG_TAG, "Unable to start playback: " + ex); } }