我正在尝试从对话框中打开一个文件,然后在 XNA 中使用 MediaPlayer 播放它,但是,我的打开器将文件作为 Stream 类打开,我不知道如何将它转换为 Song 类,所以我可以用 MediaPlayer 播放,有帮助吗?
Stream myStream = null;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "mp3 files (*.mp3)|*.mp3|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK) {
try {
if ((myStream = openFileDialog1.OpenFile()) != null) {
using (myStream) {
}
}
} catch (Exception ex) {
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}