Alexxander Posted May 5, 2014 Posted May 5, 2014 (edited) hi all i found this awesome MPC api expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <SendMessage.au3> #Include <WinAPI.au3> ; FROM MpcApi.h : ; ;~ // This file define commands used for "Media Player Classic - Homecinema" API. To send commands ;~ // to mpc-hc, and receive playback notifications, first launch process with the /slave command line ;~ // argument follow by an HWnd handle use to receive notification : ;~ // ;~ // ..\bin\mplayerc /slave 125421 ;~ // ;~ // After startup, mpc-hc send a WM_COPYDATA message to host with COPYDATASTRUCT struct filled with : ;~ // - dwData : CMD_CONNECT ;~ // - lpData : Unicode string containing mpc-hc main window Handle ;~ // ;~ // To pilot mpc-hc, send WM_COPYDATA messages to Hwnd provided on connection. All messages should be ;~ // formatted as Unicode strings. For commands or notifications with multiple parameters, values are ;~ // separated by | ;~ // If a string contains a |, it will be escaped with a \ so a \| is not a separator ;~ // ;~ // Ex : When a file is openned, mpc-hc send to host the "now playing" notification : ;~ // - dwData : CMD_NOWPLAYING ;~ // - lpData : title|author|description|filename|duration ;~ #pragma once ;~ typedef enum MPC_LOADSTATE ;~ { ;~ MLS_CLOSED, ;~ MLS_LOADING, ;~ MLS_LOADED, ;~ MLS_CLOSING ;~ }; ;~ typedef enum MPC_PLAYSTATE ;~ { ;~ PS_PLAY = 0, ;~ PS_PAUSE = 1, ;~ PS_STOP = 2, ;~ PS_UNUSED = 3 ;~ }; ;==== Commands from MPC to host ; // Send after connection ; // Par 1 : MPC window handle (command should be send to this HWnd) Global Const $CMD_CONNECT = 0x50000000 ; // Send when opening or closing file ; // Par 1 : current state (see MPC_LOADSTATE enum) Global Const $CMD_STATE = 0x50000001 ; // Send when playing, pausing or closing file ; // Par 1 : current play mode (see MPC_PLAYSTATE enum) Global Const $CMD_PLAYMODE = 0x50000002 ; // Send after opening a new file ; // Par 1 : title ; // Par 2 : author ; // Par 3 : description ; // Par 4 : complete filename (path included) ; // Par 5 : duration in seconds Global Const $CMD_NOWPLAYING = 0x50000003 ; // List of subtitle tracks ; // Par 1 : Subtitle track name 0 ; // Par 2 : Subtitle track name 1 ; // ... ; // Par n : Active subtitle track, -1 if subtitles disabled ; // ; // if no subtitle track present, returns -1 ; // if no file loaded, returns -2 Global Const $CMD_LISTSUBTITLETRACKS = 0x50000004 ; // List of audio tracks ; // Par 1 : Audio track name 0 ; // Par 2 : Audio track name 1 ; // ... ; // Par n : Active audio track ; // ; // if no audio track present, returns -1 ; // if no file loaded, returns -2 Global Const $CMD_LISTAUDIOTRACKS = 0x50000005 ; // List of files in the playlist ; // Par 1 : file path 0 ; // Par 2 : file path 1 ; // ... ; // Par n : active file, -1 if no active file Global Const $CMD_PLAYLIST = 0x50000006 ; ==================================================================== ; ==== Commands from host to MPC ; // Open new file ; // Par 1 : file path Global Const $CMD_OPENFILE = 2684354560 ; 0xA0000000 ; // Stop playback, but keep file / playlist Global Const $CMD_STOP = 2684354561 ; 0xA0000001 ; // Stop playback and close file / playlist Global Const $CMD_CLOSEFILE = 2684354562 ; 0xA0000002 ; // Pause or restart playback Global Const $CMD_PLAYPAUSE = 0xA0000003 ; // Add a new file to playlist (did not start playing) ; // Par 1 : file path Global Const $CMD_ADDTOPLAYLIST = 0xA0001000 ; // Remove all files from playlist Global Const $CMD_CLEARPLAYLIST =0xA0001001 ; // Start playing playlist Global Const $CMD_STARTPLAYLIST = 0xA0001002 ; CMD_REMOVEFROMPLAYLIST = 0xA0001003, // TODO ; // Cue current file to specific position ; // Par 1 : new position in seconds Global Const $CMD_SETPOSITION = 0xA0002000 ; // Set the audio delay ; // Par 1 : new audio delay in ms Global Const $CMD_SETAUDIODELAY = 0xA0002001 ; // Set the subtitle delay ; // Par 1 : new subtitle delay in ms Global Const $CMD_SETSUBTITLEDELAY = 0xA0002002 ; // Set the active file in the playlist ; // Par 1 : index of the active file, -1 for no file selected ; // DOESN'T WORK Global Const $CMD_SETINDEXPLAYLIST = 0xA0002003 ; // Set the audio track ; // Par 1 : index of the audio track Global Const $CMD_SETAUDIOTRACK = 0xA0002004 ; // Set the subtitle track ; // Par 1 : index of the subtitle track, -1 for disabling subtitles Global Const $CMD_SETSUBTITLETRACK = 0xA0002005 ; // Ask for a list of the subtitles tracks of the file ; // return a CMD_LISTSUBTITLETRACKS Global Const $CMD_GETSUBTITLETRACKS = 0xA0003000 ; // Ask for a list of the audio tracks of the file ; // return a CMD_LISTAUDIOTRACKS Global Const $CMD_GETAUDIOTRACKS = 0xA0003001 ; // Ask for the properties of the current loaded file ; // return a CMD_NOWPLAYING Global Const $CMD_GETNOWPLAYING = 0xA0003002 ; // Ask for the current playlist ; // return a CMD_PLAYLIST Global Const $CMD_GETPLAYLIST = 0xA0003003 ;== End MPC Commands Global $gs_messages Global $ghnd_MPC_handle GUIRegisterMsg($WM_COPYDATA, "__Msg_WM_COPYDATA") ; GUI start $Form1 = GUICreate("MPC-HC remote demo", 608, 408, 180, 120) $Edit1 = GUICtrlCreateEdit("", 16, 16, 577, 321) $Button_open = GUICtrlCreateButton("Open File", 24, 368, 140, 28, 0) $Button_play = GUICtrlCreateButton("Play / Pause", 224, 368, 140, 28, 0) $Button_stop = GUICtrlCreateButton("Stop", 424, 368, 140, 28, 0) GUISetState(@SW_SHOW) ; GUI end ; Run MPC-HC with our GUI form handle $s_formHandle = Dec(StringMid(String($Form1),3)) $pid_MPC = Run("mplayerc.exe /slave " & $s_formHandle) If $pid_MPC = 0 Then MsgBox(0,"Error","Could not run Mplayerc.exe (Path?)") Exit EndIf ;GUI loop While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button_open $s_FileToOpen = FileOpenDialog("Open Media File","C:","Media files (*.*)") __MPC_send_message($ghnd_MPC_handle, $CMD_OPENFILE, $s_FileToOpen) Case $Button_play __MPC_send_message($ghnd_MPC_handle, $CMD_PLAYPAUSE, "") Case $Button_stop __MPC_send_message($ghnd_MPC_handle, $CMD_STOP, "") EndSwitch WEnd Func __MPC_send_message($prm_hnd_MPC, $prm_MPC_Command,$prm_MPC_parameter) Local $StructDef_COPYDATA Local $st_COPYDATA Local $p_COPYDATA Local $st_CDString Local $p_CDString Local $i_StringSize $StructDef_COPYDATA = "dword dwData;dword cbData;ptr lpData"; 32 bit command; length of string; pointer to string $st_COPYDATA = DllStructCreate($StructDef_COPYDATA) ; create the message struct $i_StringSize = StringLen($prm_MPC_parameter) + 1 ; +1 for null termination $st_CDString = DllStructCreate("wchar var1[" & $i_StringSize & "]") ; the array to hold the unicode string we are sending DllStructSetData($st_CDString,1,$prm_MPC_parameter) ; set parameter string DllStructSetData($st_CDString,1,0,$i_StringSize) ; null termination $p_CDString = DllStructGetPtr($st_CDString) ; the pointer to the string DllStructSetData($st_COPYDATA, "dwData", $prm_MPC_Command) ; dwData 32 bit command DllStructSetData($st_COPYDATA, "cbData", $i_StringSize * 2) ; size of string * 2 for unicode DllStructSetData($st_COPYDATA, "lpData", $p_CDString) ; lpData pointer to data $p_COPYDATA = DllStructGetPtr($st_COPYDATA) ; pointer to COPYDATA struct _SendMessage($prm_hnd_MPC,$WM_COPYDATA,0,$p_COPYDATA) $st_COPYDATA = 0 ; free the struct $st_CDString = 0 ; free the struct EndFunc Func __Msg_WM_COPYDATA($hWnd, $Msg, $wParam, $lParam) ; Receives WM_COPYDATA message from MPC ; $LParam = pointer to a COPYDATA struct Local $StructDef_COPYDATA Local $st_COPYDATA Local $StructDef_DataString Local $st_DataString Local $s_DataString Local $s_dwData, $s_cbData, $s_lpData $StructDef_COPYDATA = "dword dwData;dword cbData;ptr lpData" $StructDef_DataString = "char DataString" $st_COPYDATA = DllStructCreate($StructDef_COPYDATA, $LParam) $s_dwData = DllStructGetData($st_COPYDATA,"dwData") ; 32bit MPC command $s_cbData = DllStructGetData($st_COPYDATA,"cbData") ; length of DataString $s_lpData = DllStructGetData($st_COPYDATA,"lpData") ; pointer to DataString $StructDef_DataString = "wchar DataString[" & int($s_cbData) & "]" ;unicode string with length cbData $st_DataString = DllStructCreate($StructDef_DataString,$s_lpData) $s_DataString = DllStructGetData($st_DataString,"DataString") ; If we receive a 0x50000000 CMD_CONNECT we retrieve the MPC handle If $s_dwData = 1342177280 Then $ghnd_MPC_handle = $s_DataString EndIf $gs_messages = __MPC_Command_to_Text($s_dwData) & @CRLF & "Data: " & $s_DataString & @CRLF & $gs_messages GUICtrlSetData($Edit1, $gs_messages) EndFunc Func __MPC_Command_to_Text($prm_MPC_Command) ; Converts an MPC command code to plain text; accepts the decimal value of the command Switch $prm_MPC_Command Case 1342177280 ;0x50000000 $s_return_msg = "CMD_CONNECT" Case 1342177281 ;0x50000000 $s_return_msg = "CMD_STATE" Case 1342177282 ;0x50000002 $s_return_msg = "CMD_PLAYMODE" Case 1342177283 ;0x50000003 $s_return_msg = "CMD_NOWPLAYING" Case 1342177284 ;0x50000004 $s_return_msg = "CMD_LISTSUBTITLETRACKS" Case 1342177285 ;0x50000005 $s_return_msg = "CMD_LISTAUDIOTRACKS" Case 1342177286 ;0x50000006 $s_return_msg = "CMD_PLAYLIST" Case Else $s_return_msg = "CMD_NO_or_UNKNOWN_CMD" EndSwitch Return $s_return_msg EndFunc thanks for ZoSTeR as you see the scrip is very long and complicated for me i only want to play a sound file at the script dir called (test.mp3) and when the play has finished i want to have a msg tell that the file playing is finished i dont want any GUI or file select. i tried to shrink it so it have only the stuff i need but i failed can any 1 help ? PS: the creator of the script is offline Since 2009 Edited May 5, 2014 by Alexxander
JohnOne Posted May 5, 2014 Posted May 5, 2014 If you want simple then use SoundPlay() AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Alexxander Posted May 5, 2014 Author Posted May 5, 2014 i tried SoundPlay() and _SoundPlay() but with no success for my files maybe my fils codec is not supported i cant even play them on wmp they only work on mpc
iamtheky Posted May 5, 2014 Posted May 5, 2014 i would guess you could get away with something similar to: runwait ("mplayerc.exe /play /close 'filename' ") msgbox(0, '' ,'done') Alexxander 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Alexxander Posted May 5, 2014 Author Posted May 5, 2014 i would guess you could get away with something similar to: runwait ("mplayerc.exe /play /close 'filename' ") msgbox(0, '' ,'done') mpc is notifying a failed to render file error had you tried this ?
BrewManNH Posted May 5, 2014 Posted May 5, 2014 Have you tried converting your files to something that wmp will play? Have you tried it with the BASS UDF? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Alexxander Posted May 5, 2014 Author Posted May 5, 2014 Have you tried converting your files to something that wmp will play? Have you tried it with the BASS UDF? i cant use converting files it will take time and my script must have the latest commands as possible and fastest execute time no i never heard about bass udf what it is cabble of ?
BrewManNH Posted May 5, 2014 Posted May 5, 2014 You can find BASS >here, and here's a description of what it is. BASS Function Library This library is a wrapper for the powerful Bass.DLL and add-ons (which increase the functionality of Bass.DLL). Bass.DLL is ideal for use in your applications and scripts if you want an easy way to play a vast range of music and sound files formats while keeping dependency on just Bass.dll and it's add-ons (which in turn maximizes compatibility and minimizes extra requirements for your software to run.), while retaining a small file size. The UDFs included with the release are: You might want to find the posts by eukalyptus near the end of the thread, he has an updated version of the UDF. You can get it at either of the following links http://www.autoit.de/index.php?page=Thread&postID=215291#post215291 https://docs.google.com/uc?export=download&id=0B12PqMKLAB1vYVpXYnl2UEtucFk Alexxander 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Alexxander Posted May 5, 2014 Author Posted May 5, 2014 You can find BASS >here, and here's a description of what it is. You might want to find the posts by eukalyptus near the end of the thread, he has an updated version of the UDF. You can get it at either of the following links http://www.autoit.de/index.php?page=Thread&postID=215291#post215291 https://docs.google.com/uc?export=download&id=0B12PqMKLAB1vYVpXYnl2UEtucFk what the hell is that i can see about 1000 file i dont even know how to play a file it is so advanced bro all what i need is to play an amr codec file and do some stuff untill the file playing is over i get a msgbox any 1 can give me a simple solution ?
JohnOne Posted May 5, 2014 Posted May 5, 2014 What is the file extension mp3 or amr AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Alexxander Posted May 5, 2014 Author Posted May 5, 2014 What is the file extension mp3 or amr codec: AMR Narrowband format: mp4 it is an audio not video and it still run when i change the extension to mp3 any help is highly appreciated
JohnOne Posted May 5, 2014 Posted May 5, 2014 (edited) VLC media player claims it can play almost any file, you should try that. Probably a command line to do it as with MPC up there. Edited May 5, 2014 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Alexxander Posted May 5, 2014 Author Posted May 5, 2014 VLC media player claims it can play almost any file, you should try that. Probably a command line to do it as with MPC up there. i can play my file through mpc but i only to shrink that mpc api to play command and finished playing msgbox
Alexxander Posted May 5, 2014 Author Posted May 5, 2014 finally could get it working after installing shark007 codecs and using WMMedia.au3 udf thank you all
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now