public void OnAudioFocusChange([GeneratedEnum] AudioFocus focusChange)
        {
            switch (focusChange)
            {
            case AudioFocus.Gain:
                musicaplayer.SetVolume(1.0f, 1.0f);    //Turn it up!
                break;

            case AudioFocus.Loss:
                //We have lost focus stop!
                musicaplayer.SetVolume(0f, 0f);    //turn it down!
                break;

            case AudioFocus.LossTransient:
                //We have lost focus for a short time, but likely to resume so pause
                musicaplayer.SetVolume(0f, 0f);
                break;

            case AudioFocus.LossTransientCanDuck:
                //We have lost focus but should till play at a muted 10% volume
                if (musicaplayer.IsPlaying)
                {
                    musicaplayer.SetVolume(.1f, .1f);    //turn it down!
                }
                break;
            }
        }
Ejemplo n.º 2
0
 private void ToggleMute()
 {
     if (IsMuted)
     {
         _player?.SetVolume(0, 0);
     }
     else
     {
         var volume = (float)Volume / 100;
         _player?.SetVolume(volume, volume);
     }
 }
        ///<Summary>
        /// Sets the playback volume as a double between 0 and 1
        /// Sets both left and right channels
        ///</Summary>
        void SetVolume(double volume, double balance)
        {
            volume = Math.Max(0, volume);
            volume = Math.Min(1, volume);

            balance = Math.Max(-1, balance);
            balance = Math.Min(1, balance);

            // Using the "constant power pan rule." See: http://www.rs-met.com/documents/tutorials/PanRules.pdf
            var left  = Math.Cos((Math.PI * (balance + 1)) / 4) * volume;
            var right = Math.Sin((Math.PI * (balance + 1)) / 4) * volume;

            player?.SetVolume((float)left, (float)right);
        }
Ejemplo n.º 4
0
 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();
     }
 }
Ejemplo n.º 5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            sensorManager = (SensorManager)GetSystemService(SensorService);
            mp            = MediaPlayer.Create(this, Resource.Raw.test);
            volume        = 0.5f;
            mp.SetVolume(volume, volume);

            SeekBar seekBar = FindViewById <SeekBar>(Resource.Id.seekBar);

            seekBar.SetOnSeekBarChangeListener(this);
            seekBar.Progress = (int)(volume * 100);

            textView      = FindViewById <TextView>(Resource.Id.textView);
            textView.Text = string.Format("Volume {0}\nProgress {1}", volume, seekBar.Progress);
        }
Ejemplo n.º 6
0
 public void OnProgressChanged(SeekBar seekBar, int progress, bool fromUser)
 {
     volume = seekBar.Progress / 100f;
     mp.SetVolume(volume, volume);
 }
Ejemplo n.º 7
0
 public void OnProgressChanged(SeekBar seekBar, int progress, bool fromUser)
 {
     volume = seekBar.Progress / 100f;
     mp.SetVolume(volume, volume);
     textView.Text = string.Format("Volume {0}\nProgress {1}", volume, seekBar.Progress);
 }
Ejemplo n.º 8
0
        void InitBeepSound()
        {
            if(playBeep && mediaPlayer == null)
            {
                VolumeControlStream = Android.Media.Stream.Music;
                mediaPlayer = new MediaPlayer();
                mediaPlayer.SetAudioStreamType(Android.Media.Stream.Music);
                mediaPlayer.SetOnCompletionListener(beepListener);

                var file = Resources.OpenRawResourceFd(BeepResource);
                try{
                    mediaPlayer.SetDataSource(file.FileDescriptor, file.StartOffset, file.Length);

                    file.Close();
                    mediaPlayer.SetVolume(0.1f, 0.1f);
                    mediaPlayer.Prepare();
                }
                catch(Java.IO.IOException e)
                {
                    mediaPlayer = null;
                }
            }
        }