c# 窗体背景音乐重复循环播放

shuchong0707 2008-09-20 09:51:11
我在主窗体中加了一个背景音乐,我想让这首背景音乐在我所有窗体里都能循环播放,该怎样弄?
...全文
1355 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
八叔 2012-05-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
添加引用 quartz.dll
C# code
void playmusic()
{
string mp3File=Application.StartupPath+"\\mp3\\你若成风.mp3";
QuartzTypeLib.FilgraphManager graphManager=new QuartzTypeLib.FilgraphManager ;
……
[/Quote]
使用quartz.dll(DX提供的一个音频解码类),然后在播放结束事件中,再次调用 mycontrol.Run() 就可实现循环播放了
请问这个“播放结束事件”怎么写?
Rich_man 2012-02-17
  • 打赏
  • 举报
回复
刚学,学习一下!
majkl 2011-12-21
  • 打赏
  • 举报
回复
回帖看三楼
梦翰斌纷 2011-07-08
  • 打赏
  • 举报
回复
不错,学习了……
LoveTXJ1988 2010-11-26
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zswang 的回复:]
C# code
using System.Runtime.InteropServices;

public static uint SND_ASYNC = 0x0001; // play asynchronously
public static uint SND_FILENAME = 0x00020000; // name is file name
[DllImport("winmm……
[/Quote]
怎么实现暂停啊?
anshuiyuer 2009-08-31
  • 打赏
  • 举报
回复
我要看代码!!!
Houkey 2008-12-13
  • 打赏
  • 举报
回复
谢谢3楼
Houkey 2008-12-13
  • 打赏
  • 举报
回复
谢谢3楼
jingang123gz 2008-11-04
  • 打赏
  • 举报
回复
C# 读取某一固定目录下的所有音频和视频文件,随机连续播放,放完一个音频或视频接着放下一个
怎么实现啊?请高手帮忙!

//Opacity
//存储音频或视频路径
//string MUSpath=null;

//读取当前目录名
string currentDir = Directory.GetCurrentDirectory();

//以此为根目录,读取MUSIC下面的文件,存储到字符串数组MUSFiles
string[] MUSFiles=Directory.GetFiles(currentDir+"\\MUSIC\\".ToString());

//以MUSIC下面的文件个数为上限,从0开始产生随机数
//将产生的随机数作为字符串数组MUSFiles下标,
//通过此下标来指定要显示的文件名
Random r=new Random ();

//播放获取的音频或视频文件
.......................请帮忙.............
shuchong0707 2008-09-21
  • 打赏
  • 举报
回复
对了,请问一楼的,那个状态改变事件是什么?
shuchong0707 2008-09-21
  • 打赏
  • 举报
回复
如果我想通过音乐停止播放这个事件来实现窗体切换,可以吗?就是说,每一个窗体都有一首音乐,每一个窗体的音乐一旦播放完就自动切换到下一个窗体,可以吗?
霜寒月冷 2008-09-20
  • 打赏
  • 举报
回复
刚刚点错按钮额,呵呵,真的是重复播放的额啊!!
霜寒月冷 2008-09-20
  • 打赏
  • 举报
回复
试了下,好像没有声音了的啊
霜寒月冷 2008-09-20
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zswang 的回复:]
C# codeusing System.Runtime.InteropServices;

public static uint SND_ASYNC = 0x0001; // play asynchronously
public static uint SND_FILENAME = 0x00020000; // name is file name
[DllImport("winmm.dll")]
public static extern uint mciSendString(string lpstrCommand,
string lpstrReturnString, uint uReturnLength, uint hWndCallback);

private void button1_Click(object sender, EventArgs e)

[/Quote]
厉害,我也来试试看!呵呵
ZengHD 2008-09-20
  • 打赏
  • 举报
回复
原来LZ的头像是基德啊

王集鹄 2008-09-20
  • 打赏
  • 举报
回复
using System.Runtime.InteropServices;

public static uint SND_ASYNC = 0x0001; // play asynchronously
public static uint SND_FILENAME = 0x00020000; // name is file name
[DllImport("winmm.dll")]
public static extern uint mciSendString(string lpstrCommand,
string lpstrReturnString, uint uReturnLength, uint hWndCallback);

private void button1_Click(object sender, EventArgs e)
{
mciSendString(@"close temp_alias", null, 0, 0);
mciSendString(@"open ""E:\音乐\周杰伦-东风破.mp3"" alias temp_alias",
null, 0, 0);
mciSendString("play temp_alias repeat", null, 0, 0);
}


Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" ( _
ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" ( _
ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As UInteger, ByVal hWndCallback As UInteger) As Long
Const SND_ASYNC As Integer = &H1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
sndPlaySound("chord", SND_ASYNC)
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mciSendString("close temp_alias", Nothing, 0, 0)
mciSendString("open ""E:\音乐\周杰伦-东风破.mp3"" alias temp_alias", Nothing, 0, 0)
mciSendString("play temp_alias repeat", Nothing, 0, 0)
End Sub
hyblusea 2008-09-20
  • 打赏
  • 举报
回复
添加引用 quartz.dll

void playmusic() 
{
string mp3File=Application.StartupPath+"\\mp3\\你若成风.mp3";
QuartzTypeLib.FilgraphManager graphManager=new QuartzTypeLib.FilgraphManager ;
QuartzTypeLib.IMediaControl mycontrol=(QuartzTypeLib.IMediaControl)graphManager;
mycontrol.RenderFile(mp3File);
mycontrol.Run();
}


使用quartz.dll(DX提供的一个音频解码类),然后在播放结束事件中,再次调用 mycontrol.Run() 就可实现循环播放了
ZengHD 2008-09-20
  • 打赏
  • 举报
回复
你是怎么播放音乐的?
一般都有“状态改变事件”,在这个事件里判断状态是不是停止状态,如果是,那就再播放一次

111,130

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧