我的文件中有一些 MP3 音频,我想在 WPF 中使用按钮播放它们,例如有三个按钮:上一个、开始、下一个。当我单击开始按钮时,正在播放第一个音频,当我单击下一个时,当我单击上一个时正在播放下一个音频,它会转到上一个音频并播放它......我试过:
string[] fileNames;
int iCurrentImageCount;
int iMaxImageCount;
private void SwipeLeftProcess()
{
if (iCurrentImageCount > 0)
iCurrentImageCount--;
else
iCurrentImageCount = iMaxImageCount - 1;
PlayAudio();
}
private void SwipeRightProcess()
{
if (iCurrentImageCount < iMaxImageCount - 1)
iCurrentImageCount++;
else
iCurrentImageCount = 0;
PlayAudio();
}
private void PlayAudio()
{
MediaPlayer ap = new MediaPlayer();
ap.Open(new Uri("/StoryAudio/" + fileNames[iCurrentImageCount], UriKind.Relative)); /ERROR here
ap.Play();
}
private void button3_Click(object sender, RoutedEventArgs e) // Start
{
PlayAudio();}
我这样做对吗?当我为图像而不是音频做时,我可以这样做,ap.Open 出现错误,说明它为空。