从程序内部播放音乐(将音乐文件添加到项目中) [英] playing music from inside the program(adding music file to project)

查看:103
本文介绍了从程序内部播放音乐(将音乐文件添加到项目中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以从程序中播放音乐,但不能通过提供文件地址来提供.

I was wondering if there was a way to play music from within the program but not by giving the address of the file.

推荐答案

mz ..


试试这个
http://www.dotnetcurry.com/ShowArticle.aspx?ID=115&AspxAutoDetectCookieSupport=1




问候,
saran.t
Hi mz..


Just try this
http://www.dotnetcurry.com/ShowArticle.aspx?ID=115&AspxAutoDetectCookieSupport=1




regards,
saran.t


如何播放WAV文件
要播放WAV文件,只需创建一个新的SoundPlayer对象,将SoundLocation属性设置为WAV文件的位置,然后使用Play方法即可播放它.

System.Media.SoundPlayer播放器=新的System.Media.SoundPlayer();
player.SoundLocation =我的Wav File.wav";
player.Play();


如何播放MP3文件
使用C#播放MP3与播放WAV一样容易,除了它要求您使用Window Media Player COM组件.因此,首先,添加对wmp.dll的引用,您可以在System32目录中找到该引用.这是一个如何播放MP3文件的示例:

WMPLib.WindowsMediaPlayer wplayer =新的WMPLib.WindowsMediaPlayer();
wplayer.URL =我的MP3文件.mp3";
wplayer.controls.play();
How to Play a WAV file
To play the WAV file simply create a new SoundPlayer object, set the SoundLocation property to the location of your WAV file, and then use the Play method to play it.

System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = "My Wav File.wav";
player.Play();


How to Play an MP3 file
Playing an MP3 with C# is just as easy as playing a WAV except that it requires you to use the Window Media Player COM component. So first, add a reference to wmp.dll, which you can find in the System32 directory. Here is an example of how to play an MP3 file:

WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.URL = "My MP3 file.mp3";
wplayer.controls.play();


这篇关于从程序内部播放音乐(将音乐文件添加到项目中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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