public void AdjustVolume(double level) { float volume = (float)(level / 100.0); if (volume == 0.0) { volume = 0.1f; } _audioPlayer.SetVolume(volume, 0); }
public void SetVolume(bool isUp) { if (isUp) { _mediaPlayer?.SetVolume(0, 0); } else { _mediaPlayer?.SetVolume(1, 1); } }
public void SetVolume(double volume) { volume = Math.Max(0, volume); volume = Math.Min(1, volume); player.SetVolume((float)volume, (float)volume); }
public void SetVolume(float leftVolume, float rightVolume) { mLeftVolume = leftVolume; mRightVolume = rightVolume; if (mAudioPlayer != null) { mAudioPlayer.SetVolume(leftVolume, rightVolume); } }
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; }
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; }
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(); } }
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); }
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); }
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; }
public void Play() { _audioPlayer?.SetVolume(1, 0); _audioPlayer?.Play(); }