コード例 #1
0
        public void AdjustVolume(double level)
        {
            float volume = (float)(level / 100.0);

            if (volume == 0.0)
            {
                volume = 0.1f;
            }

            _audioPlayer.SetVolume(volume, 0);
        }
コード例 #2
0
 public void SetVolume(bool isUp)
 {
     if (isUp)
     {
         _mediaPlayer?.SetVolume(0, 0);
     }
     else
     {
         _mediaPlayer?.SetVolume(1, 1);
     }
 }
コード例 #3
0
        public void SetVolume(double volume)
        {
            volume = Math.Max(0, volume);
            volume = Math.Min(1, volume);

            player.SetVolume((float)volume, (float)volume);
        }
コード例 #4
0
 public void SetVolume(float leftVolume, float rightVolume)
 {
     mLeftVolume  = leftVolume;
     mRightVolume = rightVolume;
     if (mAudioPlayer != null)
     {
         mAudioPlayer.SetVolume(leftVolume, rightVolume);
     }
 }
コード例 #5
0
 protected void Init(MusicStream Wave)
 {
     _mode = (AudioTrackMode)Wave.Mode;
     if (_mode == AudioTrackMode.Static)
     {
         _player = new AudioTrack(
             // Stream type
             (Android.Media.Stream)Wave.Type,
             // Frequency
             Wave.SampleRate,
             // Mono or stereo
             (ChannelOut)Wave.Config,
             // Audio encoding
             (Encoding)Wave.Format,
             // Length of the audio clip.
             (int)Wave.SizeInBytes,
             // Mode. Stream or static.
             AudioTrackMode.Static);
     }
     else
     {
         _player = new AudioTrack(
             // Stream type
             (Android.Media.Stream)Wave.Type,
             // Frequency
             Wave.SampleRate,
             // Mono or stereo
             (ChannelOut)Wave.Config,
             // Audio encoding
             (Encoding)Wave.Format,
             // Length of the audio clip.
             _buffersize = AudioTrack.GetMinBufferSize(Wave.SampleRate,
                                                       (ChannelOut)Wave.Config, (Encoding)Wave.Format),
             // Mode. Stream or static.
             AudioTrackMode.Stream);
     }
     _duration = Wave.Duration;
     _loop     = Wave.Loop;
     _frames   = Wave.Samples;
     _player.SetVolume(_volume = Wave.Volume);
     _player.SetNotificationMarkerPosition(_frames * 31 / 32);
     if (_mode == AudioTrackMode.Static)
     {
         _player.Write(Wave.Content.ReadFully(true), 0, (int)Wave.Content.Length);
     }
     else
     {
         Set((sender, e) => { if (_loop)
                              {
                                  _player.Release(); Init(_Wave); Write();
                              }
                              ; });
         _content = Wave.Content.ReadFully(true);
     }
     _prepared = true;
 }
コード例 #6
0
            protected void Init(MusicStream Wave)
            {// To get preferred buffer size and sampling rate.
                AudioManager audioManager = (AudioManager)
                                            Forms.Context.GetSystemService(Android.Content.Context.AudioService);

                Rate = int.Parse(audioManager.GetProperty(AudioManager.PropertyOutputSampleRate));
                //string Size = audioManager.GetProperty(AudioManager.PropertyOutputFramesPerBuffer);
                SampleRate = Wave.SampleRate;

                _content = Wave.Content;
                int SizeInBytes = Wave.SizeInBytes - 44;

                _player = new AudioTrack(
                    // Stream type
                    (Android.Media.Stream)Wave.Type,
                    // Frequency
                    Rate,
                    // Mono or stereo
                    (ChannelOut)Wave.Config,
                    // Audio encoding
                    (Encoding)Wave.Format,
                    // Length of the audio clip.
                    SizeInBytes,
                    // Mode. Stream or static.
                    (AudioTrackMode)Wave.Mode);
                _loop   = Wave.Loop;
                _volume = Wave.Volume;
                _player.SetVolume(_volume = Wave.Volume);
#if true
                //int ch = Wave.Channels;
                //_start = 0;// (int)Wave.Content.Length / ch;
                //_stop = (int)Wave.Content.Length;// / ch / 2 / 2 + 16000
#elif false
                _player.SetNotificationMarkerPosition(SizeInBytes / 2);
                _player.MarkerReached += (object sender, AudioTrack.MarkerReachedEventArgs e) =>
                { if (_loop)
                  {
                      e.Track.SetPlaybackHeadPosition(0);
                  }
                };
#elif false
                Device.StartTimer(Wave.Duration, () => { if (_loop)
                                                         {
                                                             _player.SetPlaybackHeadPosition(0);
                                                         }
                                                         return(_loop); });
#endif
                _prepared = true;
            }
コード例 #7
0
 public void ToggleEngine()
 {
     if (_audioPlayer != null)
     {
         _audioPlayer.FinishedPlaying -= OnMediaCompleted;
         _audioPlayer.Stop();
         _audioPlayer = null;
     }
     else
     {
         string localUrl = "Sounds/engine.m4a";
         _audioPlayer = AVAudioPlayer.FromUrl(NSUrl.FromFilename(localUrl));
         _audioPlayer.SetVolume(0.1f, 0);
         _audioPlayer.FinishedPlaying += OnMediaCompleted;
         _audioPlayer.Play();
     }
 }
コード例 #8
0
        private void SetVolume(double dVolume, double dBalance)
        {
            if (Player == null)
            {
                return;
            }

            dVolume = Math.Max(0, dVolume);
            dVolume = Math.Min(1, dVolume);

            dBalance = Math.Max(0, dBalance);
            dBalance = Math.Min(1, dBalance);

            var right = (dBalance < 0) ? dVolume * -1 * dBalance : dVolume;
            var left  = (dBalance > 0) ? dVolume * 1 * dBalance : dVolume;

            Player.SetVolume((float)left, (float)right);
        }
コード例 #9
0
        public void SetVolume(double volume, double balance)
        {
            if (player == null)
            {
                return;
            }

            volume = Math.Max(0, volume);
            volume = Math.Min(1, volume);

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

            var right = (balance < 0) ? volume * -1 * balance : volume;
            var left  = (balance > 0) ? volume * 1 * balance : volume;

            player.SetVolume((float)left, (float)right);
        }
コード例 #10
0
 protected void Init(Stream Content, bool Loop, float Volume)
 {
     _content = Content;
     _player  = new AudioTrack(
         // Stream type
         Android.Media.Stream.Music,
         // Frequency
         11025,
         // Mono or stereo
         ChannelOut.Mono,
         // Audio encoding
         Encoding.Pcm16bit,
         // Length of the audio clip.
         (int)Content.Length,
         // Mode. Stream or static.
         AudioTrackMode.Stream);
     _loop   = Loop;
     _volume = Volume;
     _player.SetVolume(_volume = Volume);
     _player.SetNotificationMarkerPosition((int)Content.Length / 2);
     _prepared = true;
 }
コード例 #11
0
ファイル: AudioService.cs プロジェクト: daniel112/xam
 public void Play()
 {
     _audioPlayer?.SetVolume(1, 0);
     _audioPlayer?.Play();
 }