Windows Phone 8 mp3 播放问题 [英] Windows Phone 8 mp3 playing problems

查看:21
本文介绍了Windows Phone 8 mp3 播放问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 wp 8 应用程序中播放 mp3,我想忘记了一些东西,你能帮忙吗

I am trying to play mp3 in my wp 8 app, i think forgot something, can you please help

我的简化代码如下:

在 page.xaml.cs 中的代码是:

in page.xaml.cs code is:

public void Play(object sender, RoutedEventArgs e)
        {


                if (PlayState.Playing == BackgroundAudioPlayer.Instance.PlayerState)
                {
                    BackgroundAudioPlayer.Instance.Pause();
                }
                else
                {
                    BackgroundAudioPlayer.Instance.Play();
                }

        }

在 App.xaml.cs 中的代码是:

in App.xaml.cs code is:

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 状态永远不会改变,但我不知道为什么(播放功能被触发)

i can see that my BackgroundAudioPlayer.Instancestate never changes, but I can't figure out why (play function is trigered)

推荐答案

您需要告诉 BackgroundAudioPlayer 要播放哪个曲目.
类似的东西:

You need to tell the BackgroundAudioPlayer which track to play.
Something like:

var track = new AudioTrack(
                           new Uri("/song.mp3", UriKind.Relative),
                           "song name",
                           "artist name",
                           "album name",
                           null); // no artwork
BackgroundAudioPlayer.Instance.Track = track;
BackgroundAudioPlayer.Instance.Play();

这篇关于Windows Phone 8 mp3 播放问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆