Quantcast
Channel: NAudio
Viewing all articles
Browse latest Browse all 5831

New Post: Best strategy to avoid gaps in playing MP3s

$
0
0

Great API! I am having 2 small problems, I get gaps when the WPF gui I created does a big visual tree rebuild on changing tabs. Once the tab is built the problem goes away. The second problem may be related, but we did a comparison of playing the same mp3 on multiple computers and the playbacks get out of phase and wander up to a second in a 20 minute mp3. This happens if you do the same test using Windows Multimedia player on multiple PCs.

What is the best strategy to avoid audio gaps and try to maintain a consistent play rate? 

Here is how I'm playing the MP3, followed by how its being opened.

publicvoid Play()
		{if (!CanPlay)return;if (waveOutDevice != null)
			{
				waveOutDevice.Play();
			}

			IsPlaying = true;
			CanPause = true;
			CanPlay = false;
			CanStop = true;
		}publicbool OpenFile( string path )
		{
			CloseFile();if (!System.IO.File.Exists(path))returnfalse;try
			{
				waveOutDevice = new WaveOut()
				{
					DesiredLatency = 100,
					NumberOfBuffers = 64,
				};
				ActiveStream = new Mp3FileReader(path);

				inputStream = new WaveChannel32(ActiveStream);
				sampleAggregator = new SampleAggregator(4096);
				inputStream.Sample += inputStream_Sample;
				waveOutDevice.Init(inputStream);
				ChannelLength = inputStream.TotalTime.TotalSeconds;
				CanPlay = true;

				GenerateWaveformData(path);

			}
			catch(Exception ex)
			{
				ActiveStream = null;
				CanPlay = false;
				log.ErrorFormat("Can not play wav file {0} - {1}", path, ex.Message);
			}return CanPlay;
		}

Thanks for any advice,

 

Neil


Viewing all articles
Browse latest Browse all 5831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>