您如何播放resource1中的音乐? [英] how do you play music from resource1?

查看:126
本文介绍了您如何播放resource1中的音乐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我有一个正在处理的项目,在该项目中是一个通过GUI创建的名为resource1的资源文件.我已将音乐添加到resource1文件中,但不确定如何从那里播放音乐.

我查阅了一些有关如何完成此工作的教程,他们在本论坛中使用了类似的方法.

http://stackoverflow.com/questions/1900707/how-to-play-audio- from-resource [ ^ ]

他们使用类似的东西:

properties.Resources.文件名"

由于某种原因,当我进入参考资料时.我无法找到音乐文件的名称来完成代码.

我也尝试过:

Hi!

I have a project that I am working on and in this project is a resource file called resource1 which I created through the GUI. I added music into the resource1 file but I am not sure how to play the music from there.

I''ve looked up some tutorials on how it''s done which they use something like in this forum.

http://stackoverflow.com/questions/1900707/how-to-play-audio-from-resource[^]

they use something like:

properties.Resources."the name of file"

For some reason when I get to the Resources. part I am unable to find the music file''s name to finish the code.

I''ve also tried this:

 SoundPlayer player = new SoundPlayer();
            player.SoundLocation.Equals(Resource1.Age_Of_Mythology_Soundtrack___Eat_Your_Potatoes);

player.Play();



感谢所有帮助,

谢谢.



Will appreciate all help,

Thanks.

推荐答案

首先是第一件事...您无需通过调用.Equal方法来设置player.SoundLocation属性.您只需将其设置为player.SoundLocation ="location Uri";无论当前声音位置是否与该字符串匹配,都不会实际设置声音位置,因此编码方式将返回true或false.

但是,您无法真正做到这一点,因为您已将声音嵌入到资源文件中.您需要使用资源管理器从.resx加载资源,然后将其加载到播放器中.这样的事情应该可以解决问题:

First thing is first... You don''t set the player.SoundLocation property by calling the .Equal method. You would simply set it like player.SoundLocation = "location Uri"; The way you have that coded would return true or false whether the current sound location matched that string never actually setting the sound location.

However, you can''t really do that because you embedded the sound in a resource file. You need to use the resource manager to load the resource from the .resx and then load it into the player. Something like this should do the trick:

ResourceManager manager = new ResourceManager("Resource1",typeof(App).Assembly);
 Stream mediaStream = manager.GetStream("Age_Of_Mythology_Soundtrack___Eat_Your_Potatoes");
 SoundPlayer player = new SoundPlayer();
 player.Stream = mediaStream;
 player.Play();



当然,必须将资源文件编译为嵌入式资源.

HTH



Of course, the resource file has to be compiled as an embedded resource.

HTH


这篇关于您如何播放resource1中的音乐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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