我正在使用VS 2015在raspberri pi 3上使用UWP,我遇到了mediaPlayer对象的问题。它工作正常,但它在每个文件的开头和结尾都有噪音,我需要逐个播放一些小MP3(或任何其他编解码器)文件,每个文件之间我听到两个噪音让我烦恼。任何机构都有解决方案。我检查了我的电脑中的文件没有噪音,这些噪音只发生在UWP中。代码如下:
async Task PlayVoice()
{
MediaPlayer player = BackgroundMediaPlayer.Current;
player.AutoPlay = true;
player.RemoveAllEffects();
player.MediaEnded += MediaPlayer_Loop;
player.Volume = 1;
player.SetUriSource(new Uri("ms-appx:///Assets/Sound/" + f[vc] + ".mp3"));
vc++;
}
void MediaPlayer_Loop(MediaPlayer player, object e)
{
if (player == null)
return;
if (vc >= f.Length)
return;
player.SetUriSource(new Uri("ms-appx:///Assets/Sound/" + f[vc] + ".mp3"));
vc++;
}
答案 0 :(得分:0)
音频停止后,在下一个音频开始之前,它们之间存在间隙,这是听众烦恼的根源。您可以尝试使用MediaPlaybackList,因为items in a MediaPlaybackList are rendered using gapless playback。像这样的代码:
void PlayBackList()
{
MediaPlaybackList mediaPlaybackList;
MediaSource mediaSource;
MediaPlaybackItem mediaPlaybackItem;
MediaElement mediaElement = new MediaElement();
mediaPlaybackList = new MediaPlaybackList();
for (vc = 0; vc < f.Count; vc++)
{
mediaSource = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/Sound/" + f[vc] + ".wma"));
mediaPlaybackItem = new MediaPlaybackItem(mediaSource);
mediaPlaybackList.Items.Add(mediaPlaybackItem);
}
mediaPlaybackList.AutoRepeatEnabled = true;
mediaElement.SetPlaybackSource(mediaPlaybackList);
mediaElement.AutoPlay = true;
mediaElement.Play();
}
此外,问题在声音输出之前和声音输出停止之后显示为响亮的弹出或咔嗒声。这是因为正在使用BCM2835 CPU的PWM输出,而不是标准DAC。当PWM功能被激活时,输出电压会跳跃,从而导致爆音。更详细的解释是here。