如何播放存储在 Windows Phone 8.1 解决方案中的 mp3 文件? [英] How can I play mp3 files stored in my Windows Phone 8.1 solution?

查看:19
本文介绍了如何播放存储在 Windows Phone 8.1 解决方案中的 mp3 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在该位置的解决方案中存储了许多 mp3 文件

I have a number of mp3 files stored in my solution at the location

/Resources/mp3Files/

在 Windows Phone 8 中,我可以通过以下方式播放这些内容:

In Windows Phone 8 I was able to play these with the following:

var name = track.Item1;
var uri = new Uri("/Resources/mp3Files/sound.mp3", UriKind.Relative);

var song = Song.FromUri(name, uri);

FrameworkDispatcher.Update();
MediaPlayer.Play(song);

但是,在 Windows Phone 8.1 中这不起作用.

However, in Windows Phone 8.1 this doesn't work.

我需要做什么才能播放存储在我的解决方案中的 mp3 文件?

What do I need to do to play mp3 files I have stored in my solution?

推荐答案

这是有效的:

// get folder app is installed to
var installFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;

// get folders mp3 files are installed to.
var resourcesFolder = await installFolder.GetFolderAsync("Resources");
var mp3FilesFolder = await resourcesFolder.GetFolderAsync("mp3Files");

// open the mp3 file async
var audioFile = await mp3FilesFolder.GetFileAsync("sound.mp3");
var stream = await audioFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

// play dat funky music
MediaElement mediaplayer = new MediaElement();
mediaplayer.SetSource(stream, audioFile.ContentType);
mediaplayer.Play();

这篇关于如何播放存储在 Windows Phone 8.1 解决方案中的 mp3 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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