我在Tendy的源码的基础之上写了一款电台播放器,主要是增加了录音,优化了一些代码,纯属自用,专门用来听英语的,但最近发现一个Bug,就是使用录音功能并保存录音文件后,无论换什么台,都只会播放之前录制的那个电台,自己已经想方设法作了很多尝试,还是没用,希望大家看看。;与本问题无关的代码省略,帖子最后有可供测试的已编译文件
Dim $inifile_path="playlist.ini"
$oMediaPlayer.URL=""
$PlayList = GuiCtrlCreateCombo("", 38, 90, 170, 21) ;创建列表
$Play = GuiCtrlCreateButton("播放", 5, 60, 45, 25) ;创建播放按钮
;……
$List = IniReadSection ($inifile_path,"List")
If @error Then
MsgBox(16,"错误!","读取"&$inifile_path&"失败,程序无法继续!")
Exit
EndIf
For $I = 1 To $List[0][0]
$ComboList=$ComboList&"|"&$List[$I][0]
Next
GuiCtrlSetData($PlayList,$ComboList,$List[1][1])
GuiSetState()
;……
While 1
Local $msg = GuiGetMsg()
Select
;……
;播放列表
Case $msg=$PlayList
$oMediaPlayer.URL = IniRead ($inifile_path, "List",GUICtrlRead($PlayList),"")
$oMediaPlayControl.Play
GUICtrlSetData($Play,"停止")
;录音/保存
Case $msg=$Record
__Record()
EndSelect
WEnd
;函数
;录音(Func)
Func __SoundMciSendString($string, $iLen = 65534)
Local $iRet = DllCall('winmm.dll', 'int', 'mciSendString', 'str', $string, 'str', '', 'int', $iLen, 'hwnd', 0)
Return $iRet[2]
EndFunc
Func __Record()
Select
Case GUICtrlRead($Play)="播放"
MsgBox(0,"注意","您未收听任何电台!")
Case GUICtrlRead($Record)="录制"
__SoundMciSendString('Open New type WaveAudio alias recorder');新建录音recorder
__SoundMciSendString('set recorder bitspersample 8');使用8位
__SoundMciSendString('set recorder samplespersec 11025');11025Hz
__SoundMciSendString('set recorder channels 2');立体声(双声道)
__SoundMciSendString('record recorder');开始录音
GUICtrlSetData($Record,"保存")
Case GUICtrlRead($Record)="保存"
GUICtrlSetData($Record,"录制")
__SoundMciSendString('stop recorder')
$RecordSave = FileSaveDialog('保存录音', @DesktopDir, '录音文件 (*.wav)', 18, 'Record.wav', $Formm)
If Not @error Then __SoundMciSendString('save recorder "' & $RecordSave & '"')
__SoundMciSendString('close recorder')
EndSelect
EndFunc
下面是已编译的文件,供测试 |