Beispiel #1
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;
            }