0
我想在我的WP 8的应用程序来播放mp3,我想忘记的东西,你可以请帮的Windows Phone 8播放MP3的问题
我的简化代码,因为它有云:
在page.xaml的.cs代码:
public void Play(object sender, RoutedEventArgs e)
{
if (PlayState.Playing == BackgroundAudioPlayer.Instance.PlayerState)
{
BackgroundAudioPlayer.Instance.Pause();
}
else
{
BackgroundAudioPlayer.Instance.Play();
}
}
在App.xaml.cs代码:
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
string[] files = new string[] { "song.mp3"};
foreach (var _fileName in files)
{
if (!storage.FileExists(_fileName))
{
string _filePath = "Sounds/" + _fileName;
StreamResourceInfo resource = Application.GetResourceStream(new Uri(_filePath, UriKind.Relative));
using (IsolatedStorageFileStream file = storage.CreateFile(_fileName))
{
int chunkSize = 4096;
byte[] bytes = new byte[chunkSize];
int byteCount;
while ((byteCount = resource.Stream.Read(bytes, 0, chunkSize)) > 0)
{
file.Write(bytes, 0, byteCount);
}
}
}
}
}
}
我可以看到我BackgroundAudioPlayer.Instance
状态永不改变,但我不明白为什么(播放功能被触发)
如果你告诉它什么曲目/文件播放? –
很好通常我使用SoundEffect.Stream控制,我不熟悉 –