Пример #1
0
 public static void Dispose()
 {
     if (player != null)
     {
         isPlay = false;
         player.Stop();
         player.Dispose();
         MainActivity.GetAudioManager.AbandonAudioFocus(focus);
     }
 }
Пример #2
0
        public bool OnError(AndroidMediaPlayer mp, MediaError what, int extra)
        {
            if (PlaybackSession.PlaybackState != MediaPlaybackState.None)
            {
                _player?.Stop();
                PlaybackSession.PlaybackState = MediaPlaybackState.None;
            }

            OnMediaFailed(message: $"MediaPlayer Error: {what}");
            return(true);
        }
        void OnPlaybackEnded(object sender, EventArgs e)
        {
            PlaybackEnded?.Invoke(sender, e);

            //this improves stability on older devices but has minor performance impact
            if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.M)
            {
                player.SeekTo(0);
                player.Stop();
                player.Prepare();
            }
        }
Пример #4
0
 public void OnCompletion(MediaPlayer player)
 {
     try
     {
         player.Stop();
         player.Reset();
         player.Release();
     } catch (Exception ex)
     {
         #if DEBUG
         System.Diagnostics.Debug.WriteLine("Exception in audio {0}", ex.Message);
         #endif
     }
 }
Пример #5
0
		public void Play ()
		{
			try {
				player = MediaPlayer.Create (context, Resource.Raw.droll);
				player.Completion += (object sender, EventArgs e) => {
					player.Stop ();
					player.Release ();
					player = null;
				};
				player.Start ();
			} catch (Exception ex) {
				Console.Out.WriteLine (ex.StackTrace);
			}
		}
Пример #6
0
 public void Play(int resId)
 {
     try
     {
         if (player != null)
         {
             //if (player.IsPlaying)
             //{
             //    player.Stop();
             //    player.Reset();
             //}
             player.Reset();
         }
         player = MediaPlayer.Create(Application.Context, resid: resId);
         player.Stop();
         player.Prepare();
         player.Start();
     }
     catch (Exception ex)
     {
         System.Console.Out.WriteLine(ex.StackTrace);
     }
 }
Пример #7
0
 public void OnStop(MediaPlayer player)
 {
     player.Stop();
 }
Пример #8
0
 public void OnCompletion(MediaPlayer p)
 {
     p.Stop ();
     p.Release ();
 }
Пример #9
0
    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;
      }
    }
Пример #10
0
        protected override void OnCreate(Bundle bundle)
        {
            _player = MediaPlayer.Create (this,Resource.Raw.police_alarm);
            base.OnCreate (bundle);
            SetContentView (Resource.Layout.alarm);
            ImageButton start = FindViewById<ImageButton> (Resource.Id.Start_ALarm);
            start.Click += delegate {
                _player = MediaPlayer.Create (this,Resource.Raw.police_alarm);
                _player.Start ();

            };
            ImageButton stop = FindViewById<ImageButton> (Resource.Id.Stop_ALarm);
            stop.Click += delegate {
                _player.Stop ();
                _player.Release();
                _player=null;
            //				Intent i = new Intent (this, typeof(MainActivity));
            //				StartActivity (i);
            };
            //	FindViewById<TextView> (Resource.Id.Start_ALarm).Click+=Start_alarm_click;
            //FindViewById<TextView> (Resource.Id.Stop_ALarm).Click += Stop_alarm_click;
        }
Пример #11
0
        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);
            }
        }
Пример #12
0
                public override void OnCreate()
                {
                    base.OnCreate();

                    Rock.Mobile.Util.Debug.WriteLine( "AudioService::OnCreate" );

                    Binder = new AudioServiceBinder( this );

                    // prepare our media player
                    MediaPlayer = new MediaPlayer();
                    MediaPlayer.SetAudioStreamType( Stream.Music );
                    MediaPlayer.Stop( );
                }
Пример #13
0
                public bool OnError( MediaPlayer mp, MediaError error, int extra )
                {
                    ProgressBar.Visibility = ViewStates.Gone;

                    // only show the resultView if we're active.
                    if( FragmentActive == true )
                    {
                        ResultView.Show( MessagesStrings.Error_Title, 
                            PrivateControlStylingConfig.Result_Symbol_Failed, 
                            MessagesStrings.Error_Watch_Playback,
                            GeneralStrings.Retry );
                        
                        ResultView.SetBounds( new System.Drawing.RectangleF( 0, 0, NavbarFragment.GetFullDisplayWidth( ), this.Resources.DisplayMetrics.HeightPixels ) );
                    }

                    if( mp != null )
                    {
                        mp.Stop( );
                        mp.Reset( );
                    }

                    MediaControllerPrepared = false;

                    PlayerState = MediaPlayerState.None;

                    //SyncUI( );

                    return true;
                }