public virtual void Pause() { if (PlaybackSession.PlaybackState == MediaPlaybackState.Playing) { _player?.Pause(); PlaybackSession.PlaybackState = MediaPlaybackState.Paused; } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); ActionBar.Hide(); SetContentView(Resource.Layout.Main); cover = FindViewById<RelativeLayout>(Resource.Id.titleScreen); player = MediaPlayer.Create(this, Resource.Raw.avril_14th); toggleMusic = FindViewById<ToggleButton>(Resource.Id.toggleMusic); player.Start(); player.Looping = true; cover.Click += delegate { StartActivity(typeof(Login)); }; toggleMusic.Click += (o, s) => { if (toggleMusic.Checked) { player.Start(); toggleMusic.SetBackgroundResource(Android.Resource.Drawable.IcMediaPause); } else { toggleMusic.SetBackgroundResource(Android.Resource.Drawable.IcMediaPlay); player.Pause(); } }; }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.Inflate(Resource.Layout.HomeScreen, container, false); infoButton = view.FindViewById<Button>(Resource.Id.infoButton); player = MediaPlayer.Create(view.Context, Resource.Raw.avril_14th); toggleMusic = view.FindViewById<ToggleButton>(Resource.Id.toggleMusic); cover = view.FindViewById<RelativeLayout>(Resource.Id.titleScreen); Xamarin.Insights.Initialize(XamarinInsights.ApiKey, view.Context); CurrentPlatform.Init(); player.Start(); player.Looping = true; cover.Click += delegate { facebookLogin.Invoke(this, new LoginEventArgs()); }; toggleMusic.Click += (o, s) => { if (toggleMusic.Checked) { player.Start(); toggleMusic.SetBackgroundResource(Android.Resource.Drawable.IcMediaPause); } else { toggleMusic.SetBackgroundResource(Android.Resource.Drawable.IcMediaPlay); player.Pause(); } }; return view; }
public void OnPrepared(AndroidMediaPlayer mp) { PlaybackSession.NaturalDuration = TimeSpan.FromMilliseconds(_player.Duration); VideoRatioChanged?.Invoke(this, (double)mp.VideoWidth / global::System.Math.Max(mp.VideoHeight, 1)); if (PlaybackSession.PlaybackState == MediaPlaybackState.Opening) { UpdateVideoStretch(_currentStretch); if (_isPlayRequested) { _player.Start(); PlaybackSession.PlaybackState = MediaPlaybackState.Playing; } else { // To display first image of media when setting a new source. Otherwise, last image of previous source remains visible _player.Start(); _player.Pause(); _player.SeekTo(0); } } _isPlayerPrepared = true; }
public static void Pause() { if (isPlay) { player.Pause(); isPlay = false; isPause = true; MainActivity.GetAudioManager.AbandonAudioFocus(focus); } }
public void OnSensorChanged(SensorEvent e) { if (!mp.IsPlaying) { mp.Start(); } else { mp.Pause(); } }
public void OnSensorChanged(SensorEvent e) { if (!mp.IsPlaying) { mp.Start(); text.Text = "on"; } else { mp.Pause(); text.Text = "off"; } }
public void OnSensorChanged(SensorEvent e) { Toast.MakeText(this, "CHANGE", ToastLength.Long).Show(); play = !play; if (play) { if (!MP.IsPlaying) { MP.Start(); } Toast.MakeText(this, "START", ToastLength.Long).Show(); MP.SetVolume(0.0f, 1.0f); } else { MP.Pause(); Toast.MakeText(this, "STOP", ToastLength.Long).Show(); } }
public void OnPause(MediaPlayer player) { player.Pause(); }
///<Summary> /// Pause playback if playing (does not resume) ///</Summary> public void Pause() { player?.Pause(); }
protected async override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.PodcastDetail); var showNumber = Intent.GetIntExtra("show_number", 0); episode = Activity1.ViewModel.GetPodcast(showNumber); var description = FindViewById<TextView>(Resource.Id.descriptionView); description.Text = episode.Description; var play = FindViewById<Button>(Resource.Id.playButton); var pause = FindViewById<Button>(Resource.Id.pauseButton); var stop = FindViewById<Button>(Resource.Id.stopButton); seekBar = FindViewById<SeekBar>(Resource.Id.seekBar1); status = FindViewById<TextView>(Resource.Id.statusText); updateHandler = new Handler(); player = new MediaPlayer(); player.SetDataSource(this, Android.Net.Uri.Parse(episode.AudioUrl)); player.PrepareAsync(); player.Prepared += (sender, e) => { initialized = true; player.SeekTo(timeToSet * 1000); UpdateStatus(); }; play.Click += (sender, e) => { player.Start(); updateHandler.PostDelayed(UpdateStatus, 1000); }; pause.Click += (sender, e) => player.Pause(); stop.Click += (sender, e) => { player.Stop(); player.Reset(); player.SetDataSource(this, Android.Net.Uri.Parse(episode.AudioUrl)); player.Prepare(); }; seekBar.ProgressChanged += (sender, e) => { if (!e.FromUser) return; player.SeekTo((int)(player.Duration * ((float)seekBar.Progress / 100.0))); }; var updated = await episode.GetTimeAsync(); if (updated == null || updated.ShowNumber != episode.ShowNumber) return; if (initialized && player != null) { player.SeekTo(updated.CurrentTime * 1000); UpdateStatus(); } else { timeToSet = updated.CurrentTime; } }
public string SoundPlay(string SoundName, string messageid, string messegeCondition, string status, string CurrentSliderValue) { try { if (SoundName == "served") { player = new Android.Media.MediaPlayer(); var ffd = Xamarin.Forms.Forms.Context.Assets.OpenFd("served.mp3"); player.Reset(); player.Prepared += (s, e) => { player.Start(); }; player.SetDataSource(ffd.FileDescriptor); player.Prepare(); } else { if (status == "Play") { player = new Android.Media.MediaPlayer(); player.Reset(); player.Prepared += (s, e) => { player.Start(); }; player.SetDataSource(SoundName); player.Prepare(); Messageid = messageid; if (messegeCondition == "right_audio") { TimerSound = new System.Timers.Timer(); TimerSound.Interval = 1000; TimerSound.Elapsed += TimerSound_Elapsed; TimerSound.Start(); } else { TimerSound = new System.Timers.Timer(); TimerSound.Interval = 1000; TimerSound.Elapsed += TimerSound_ElapsedSlider; TimerSound.Start(); } } else if (status == "Stop") { player.Stop(); TimerSound.Stop(); } else if (status == "Pause") { player.Pause(); TimerSound.Stop(); } else if (status == "PauseAfterplay") { try { var Converter = CurrentSliderValue.Substring(0, CurrentSliderValue.Length - 3);; int CurrentValue = 0; CurrentValue = Int32.Parse(Converter); player.SeekTo(CurrentValue); player.Start(); TimerSound.Start(); } catch (Exception) { } } } return(player.Duration.ToString()); } catch (Exception) { return(null); } }
public void reproducir(string downloadurl, bool desdecache) { // musicaplayer.SetDataSource(downloadurl); if (playeroffline.gettearinstancia() != null) { try { musicaplayer.Release(); musicaplayer = new MediaPlayer(); #pragma warning disable 414 if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.N) { musicaplayer.SetAudioAttributes(new AudioAttributes.Builder() .SetUsage(AudioUsageKind.Media) .SetContentType(AudioContentType.Music) .Build()); } else { #pragma warning disable CS0618 // El tipo o el miembro están obsoletos musicaplayer.SetAudioStreamType(Android.Media.Stream.Music); #pragma warning restore CS0618 // El tipo o el miembro están obsoletos } #pragma warning restore 414 musicaplayer.SetWakeMode(this, WakeLockFlags.Partial); #pragma warning disable 414 #pragma warning disable CS0618 // El tipo o el miembro están obsoletos var focusResult = audioManager.RequestAudioFocus(this, Stream.Music, AudioFocus.Gain); #pragma warning restore CS0618 // El tipo o el miembro están obsoletos #pragma warning restore 414 if (focusResult != AudioFocusRequest.Granted) { //could not get audio focus Console.WriteLine("Could not get audio focus"); } musicaplayer.Prepared += delegate { musicaplayer.Start(); if (this.desdecache) { musicaplayer.Pause(); } if (playeroffline.gettearinstancia() != null) { if (playeroffline.gettearinstancia().video.Visibility == ViewStates.Visible) { musicaplayer.SetDisplay(null); musicaplayer.SetDisplay(playeroffline.gettearinstancia().holder); } if (SettingsHelper.HasKey("posactual") && this.desdecache) { var posicion = 0; try { posicion = int.Parse(SettingsHelper.GetSetting("posactual")); musicaplayer.SeekTo(posicion); } catch (Exception) { } } } }; musicaplayer.Completion += delegate { playeroffline.gettearinstancia().RunOnUiThread(() => { playeroffline.gettearinstancia().RunOnUiThread(() => { playeroffline.gettearinstancia().siguiente.PerformClick(); }); }); }; musicaplayer.SetDataSource(this, Android.Net.Uri.Parse(downloadurl.Trim())); mostrarnotificacion(); musicaplayer.PrepareAsync(); } catch (Exception) { //if() playeroffline.gettearinstancia().RunOnUiThread(() => { Toast.MakeText(playeroffline.gettearinstancia(), "Error al reproducir", ToastLength.Long).Show(); }); } } else { musicaplayer.Reset(); StopSelf(); } }
public void OnCompletion(MediaPlayer mp) { mp.SeekTo (0); mp.Pause (); }