Example #1
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;
 }
 private Track(Stream streamType, int sampleRateInHz, ChannelOut channelConfig, Encoding audioFormat, int bufferSizeInBytes, AudioTrackMode mode, int sessionId, int dataLength, byte[] data)
     :
     base(streamType, sampleRateInHz, channelConfig, audioFormat, bufferSizeInBytes, mode, sessionId)
 {
     TrackDataLength = dataLength;
     TrackData       = data;
 }