2011-01-21 77 views
0

我嘗試使用mciSendString播放高品質音樂(320kpbs),但不起作用。並且mciSendString返回值是MCIERR_INVALID_DEVICE_NAME(263)。如何解決它?如何使用mciSendString播放高品質音樂(320kpbs)

+1

我認爲比特率是無關的。我自己實現mciCommandString時遇到了麻煩。其中一個函數的返回值不正確,或者串錯了字符串。 – 2011-01-21 07:37:32

回答

0

我以前使用過mciSendString在當前打開的任何應用程序的窗口上呈現mpeg視頻。播放音頻文件幾乎完全相同,除非您將「類型」從MPEGVideo更改爲waveaudio。只要安裝了適當的編解碼器,它就會播放你的音頻。

下面是我的應用程序的源代碼,該應用程序在前景中的任何窗口上播放視頻。請檢查mciSendString文檔並檢查您的「打開」命令是否有錯誤。

format PE GUI 4.0 
entry start 

include 'win32a.inc' 

include 'helper.asm' 

section '.idata' import data readable writeable 

    library kernel32,'KERNEL32.DLL',\ 
      user32,'USER32.DLL',\ 
      hook,'HOOK.DLL',\ 
      winmm,'WINMM.DLL' 

    import hook,\ 
      SetKeyPressedHandler,'SetKeyPressedHandler' 

    import winmm,\ 
      PlaySound,'PlaySound',\ 
      mciSendString,'mciSendStringA' 

    include 'api\kernel32.inc' 
    include 'api\user32.inc' 

section '.data' data readable writeable 
    _class TCHAR 'PRANK',0 
    _title TCHAR 'Video',0 

    wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class 

    szmciClose db "close video",0 
    szmciOpenTemplate db "open video.mpg type MPEGVideo alias video parent %i style child",0 
    szmciPlay db "play video notify",0 

    ;String saying what the dll is called. 
    szDllName db "HOOK.DLL",0 

    ;Name of the function in the dll for the keyboard procedure 
    szf_KeyboardProc db "KeyboardProc",0 

    ;handle to the dll 
    hDll dd ? 
    ;handle to the keyboard procedure 
    hKeyboardProc dd ? 
    ;handle to the hook 
    hHook dd ? 
    hwnd dd ? 

    struct GUITHREADINFO 
     cbSize dd ? 
     flags dd ? 
     hwndActive dd ? 
     hwndFocus dd ? 
     hwndCapture dd ? 
     hwndMenuOwner dd ? 
     hwndMoveSize dd ? 
     hwndCaret dd ? 
     rcCaret RECT 
    ends 
    kInput KBINPUT 

    guithreadinfo GUITHREADINFO 

    keyCount dd 0x0 

    ;msg for the message pump 
    msg MSG 

section '.bss' readable writeable 
    szmciOpen rb 100h 

section '.text' code readable executable 

    start: 

     invoke GetModuleHandle,0 
     mov [wc.hInstance],eax 
     invoke LoadIcon,0,IDI_APPLICATION 
     mov [wc.hIcon],eax 
     invoke LoadCursor,0,IDC_ARROW 
     mov [wc.hCursor],eax 
     invoke RegisterClass,wc 
     invoke CreateWindowEx,0x0,_class,_title,0x0,0x0,0x0,0x0,0x0,NULL,NULL,[wc.hInstance],NULL 
     mov [hwnd],eax 


     ;Load the DLL into memory. 
     invoke LoadLibraryA,szDllName 
     cmp eax,0x0 
     je exit 
     mov [hDll],eax 


     invoke GetProcAddress,[hDll],szf_KeyboardProc 
     cmp eax,0x0 
     je freeLibrary 
     mov [hKeyboardProc],eax 

     invoke SetKeyPressedHandler,KeyPressedHandler 

    hook: 
     invoke SetWindowsHookEx,WH_KEYBOARD_LL,[hKeyboardProc],[hDll],0x0 
     cmp eax,0x0 
     je freeLibrary 
     mov [hHook],eax 

    msg_loop: 
     invoke GetMessage,msg,NULL,0,0 
     cmp eax,1 
     jb unhook 
     jne msg_loop 
     invoke TranslateMessage,msg 
     invoke DispatchMessage,msg 
    jmp msg_loop 

    proc WindowProc hwnd,wmsg,wparam,lparam 
    push ebx esi edi 

    cmp [wmsg],0x3B9 
    je .wmnotify 
    jmp .defwndproc 
    .wmnotify: 
    invoke mciSendString,szmciClose,0x0,0x0,0x0 
    jmp .done 
    .defwndproc: 
    invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam] 
    .done: 
    pop edi esi ebx 
    ret 
    endp 

    proc KeyPressedHandler code,wparam,lparam 
     ;Move the VK Code of the key they pressed into al. 
     xor eax,eax 
     mov eax,[lparam] 
     mov cx,word [eax] 

     cmp [wparam],WM_KEYDOWN 
     je .ProcessKeyDown 
     cmp [wparam],WM_KEYUP 
     je .ProcessKeyUp 

     .ProcessKeyDown: 

      ret ;No need to go any further - we only process characters on key up 
     .ProcessKeyUp: 
      mov edx,[keyCount] 
      inc edx 

      cmp cx,VK_F12 
      je unhook 

      ;Hotkeys. 
      ;F12 - Quit. 
      cmp edx,0x04 
      jne .done 
      call PlayVideo 
      xor edx,edx 
      .done: 
      mov [keyCount],edx 
     ret 
    endp 

    proc PlayVideo 
     mov [guithreadinfo.cbSize],sizeof.GUITHREADINFO 
     invoke GetGUIThreadInfo,NULL,guithreadinfo 

     cinvoke wsprintf,szmciOpen,szmciOpenTemplate,[guithreadinfo.hwndFocus] 
     invoke mciSendString,szmciOpen,0x0,0x0,0x0 
     invoke mciSendString,szmciPlay,0x0,0x0,[hwnd] 
     ret 
    endp 
    unhook: 
     invoke UnhookWindowsHookEx,[hHook] 

    freeLibrary: 
     invoke FreeLibrary,[hDll] 
    exit: 
     invoke ExitProcess,0 

以上依賴於系統級鍵盤鉤子(是的,這是一個惡作劇,是的 - 這是搞笑)

format PE GUI 4.0 DLL 
entry _DllMain 

include 'win32a.inc' 

section '.data' data readable writeable 
    hKeyPressedHandler dd 0x0 
section '.text' code readable executable 

proc _DllMain hinstDLL,fdwReason,lpvReserved 
    mov eax,TRUE 
    ret 
endp 

    proc SetKeyPressedHandler hProc 
     mov eax,[hProc] 
     mov [hKeyPressedHandler],eax 
     ret 
    endp 

    proc KeyboardProc code,wparam,lparam 
     cmp [code],0x0 
     jl CallNextHook 

     cmp [hKeyPressedHandler],0x0;Make sure our event handler is set. 
     je CallNextHook 

     ;Call our handler. 
     invoke hKeyPressedHandler,[code],[wparam],[lparam] 

     CallNextHook: 
      invoke CallNextHookEx,0x0,[code],[wparam],[lparam] 
      ret 
    endp 

section '.idata' import data readable writeable 

    library kernel32,'KERNEL32.DLL',\ 
      user32,'USER32.DLL' 

    include 'api\kernel32.inc' 
    include 'api\user32.inc' 

section '.edata' export data readable 
    export 'hook.DLL',\ 
     KeyboardProc,'KeyboardProc',\ 
     SetKeyPressedHandler,'SetKeyPressedHandler' 

section '.reloc' fixups data discardable