| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1039 人关注过本帖
标题:在VB.NET如何用多线程播放WAV文件?
只看楼主 加入收藏
xf_wolf
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-3-28
收藏
 问题点数:0 回复次数:6 
在VB.NET如何用多线程播放WAV文件?
在VB.NET如何用多线程播放WAV文件?
因为要连续播放多个WAV文件,在播放时界面没有反应,想用多线程,但不成功。关键是不知怎么传递参数。
Private Sub Grid2_Click(ByVal Sender As Object, ByVal e As System.EventArgs) Handles Grid2.Click
Dim GBdm As String
Dim iType As Integer

GBdm = Grid2.Cell(Grid2.MouseRow, 5).Text()

iType = MsgBox("你确定要广播-" + Grid2.Cell(Grid2.MouseRow, 4).Text() + "-这条信息吗?", 36, "确定广播?")
If iType = MsgBoxResult.Yes Then
T1 = New Thread(AddressOf Me.CBY_PLAY)

T1.Start()
End If
End Sub
Private Sub CBY_PLAY(ByVal BY As String)
Dim path, GBxx() As String
Dim iType, intX As Integer
path = Application.StartupPath & "\..\wav\"
GBxx = Split(BY, ":")
For intX = 0 To GBxx.Length - 1
sndPlay(path & GBxx(intX) & ".wav", 0)
Next
End Sub
Public Declare Function sndPlay Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal SoundName As String, ByVal Flags As Long) As Long
搜索更多相关主题的帖子: WAV文件 线程 NET 播放 
2006-04-08 21:23
regedit
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:950
专家分:0
注 册:2004-6-8
收藏
得分:0 
用委托吧~

最新作品:百货品牌商品资讯第一门户([url]http://www./[/url]),欢迎交流
2006-04-09 01:53
regedit
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:950
专家分:0
注 册:2004-6-8
收藏
得分:0 

Public Declare Function sndPlay Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal SoundName As String, ByVal Flags As Long) As Long
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
Public Delegate Sub PlayWAVDelegate(ByVal Path As String)
Public PlayWavAsyncCallBack As AsyncCallback
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim PlayWavThread As PlayWAVDelegate = New PlayWAVDelegate(AddressOf PlayWAV)
PlayWavAsyncCallBack = New AsyncCallback(AddressOf PlayWAV_CallBack)
PlayWavThread.BeginInvoke(TextBox1.Text, PlayWavAsyncCallBack, Nothing)
End Sub
Public Sub PlayWAV_CallBack(ByVal b As IAsyncResult)
If b.IsCompleted Then
MsgBox("播放完毕")
End If
End Sub
Private Sub PlayWAV(ByVal Path As String)
sndPlay(Path, 0)
End Sub


最新作品:百货品牌商品资讯第一门户([url]http://www./[/url]),欢迎交流
2006-04-09 01:57
xf_wolf
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-3-28
收藏
得分:0 
TEXT1.TEXT是给它的路径吗?
CBY_PLAYThread(BeginInvoke(TEXT1.TEXT, CBY_PLAYAsyncCallBack, Nothing))
这里面的TEXT1.text是传给PLAYWAVE的路径吗?
不好意思,我对VB。NET不是很熟。
2006-04-10 10:13
xf_wolf
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-3-28
收藏
得分:0 
问题解决啦,但又有新问题?

Private Sub Grid2_Click(ByVal Sender As Object, ByVal e As System.EventArgs) Handles Grid2.Click
Dim GBdm As String
Dim iType As Integer
GBdm = Grid2.Cell(Grid2.MouseRow, 5).Text()
Dim CBY_PLAYThread As CBY_PLAYDelegate = New CBY_PLAYDelegate(AddressOf CBY_PLAY)
iType = MsgBox("你确定要广播-" + Grid2.Cell(Grid2.MouseRow, 4).Text() + "-这条信息吗?", 36, "确定广播?")
If iType = MsgBoxResult.Yes Then
CBY_PLAYAsyncCallBack = New AsyncCallback(AddressOf CBY_PLAY_CallBack)
CBY_PLAYThread.BeginInvoke(GBdm, CBY_PLAYAsyncCallBack, Nothing)
End If
End Sub

Private Sub CBY_PLAY(ByVal BY As String)
Dim path, GBxx() As String
Dim intX As Integer
path = Application.StartupPath & "\..\wav\"
GBxx = Split(BY, ":")
For intX = 0 To GBxx.Length - 1
sndPlay(path & GBxx(intX) & ".wav", 0)
Next
End Sub
Public Delegate Sub CBY_PLAYDelegate(ByVal Path As String)
Public CBY_PLAYAsyncCallBack As AsyncCallback
Public Sub CBY_PLAY_CallBack(ByVal b As IAsyncResult)
If b.IsCompleted Then
MsgBox("本信息已播放完毕!", 32, "广播完毕!")
End If
End Sub
问题是我怎么判断我调用CBY_PLAY已经完毕,要不会出现播放混乱的现象。

2006-04-10 10:25
regedit
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:950
专家分:0
注 册:2004-6-8
收藏
得分:0 
CBY_PLAYAsyncCallBack,这个就是指上一个WAV已播放完毕了啊~

最新作品:百货品牌商品资讯第一门户([url]http://www./[/url]),欢迎交流
2006-04-10 15:02
xf_wolf
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-3-28
收藏
得分:0 
我试了一下,不行!
那要如何判断呢?
2006-04-10 20:01
快速回复:在VB.NET如何用多线程播放WAV文件?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020216 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved