
[Library] MCI v1.1 - Play/Control media files
Can you write some setvolume example for %selectedfile%?
I want use this in my player at:
<!-- m -->svn://autohotkey.net/vlcekp1/myrepos/player/<!-- m -->
![[Library] MCI v1.1 - Play/Control media files: post #16](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
The code for calling the MCI_SetVolume function is fairly straightforward:Can you write some setvolume example for %selectedfile%?
MCI_SetVolume(OpenMCIDevice,1000) ;-- Sets the volume to max for the device MCI_SetVolume(OpenMCIDevice,500) ;-- Sets the volume to midway point for the device MCI_SetVolume(OpenMCIDevice,0) ;-- Sets the volume to 0 (mute) for the deviceAlthough the MCI protocol supports volume change, most MCI devices do not support the associated MCI "Set Volume" command. If your player only plays media that uses MCI devices that support MCI volume change, the MCI_SetVolume function is a good choice. However, if your player plays a mix of media types (I suspect it does), AutoHotkey's SoundSet command might make more sense.
Good luck!
![[Library] MCI v1.1 - Play/Control media files: post #17](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
MCI_SetVolume(hMedia,+10) ;--
Set volume for hMedia to +10.
The player stop, when I call this function.
![[Library] MCI v1.1 - Play/Control media files: post #18](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
Just to make sure that there weren't any hidden bugs, I tried calling the function (with your parameters) on my PC and it worked without generating an error.Thanks for example, but I have problem with this.
MCI_SetVolume(hMedia,+10) ;--
Set volume for hMedia to +10.
The player stop, when I call this function.
Here's something to try: Open a debugger and check the output right after the function is called. If there is an MCI error, the function will send a user-friendly message to the debugger that will describe the problem. For example, if you call the function without opening the MCI device first, you'll get the following message: Return code=261 - The driver cannot recognize the specified command.
Good luck!
![[Library] MCI v1.1 - Play/Control media files: post #19](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
Well, first congratulations for making a library to replace
my old and deprecated Sound.ahk...
I hope you suceed with this proyect

fincs - the autor of Sound.ahk and Media.ahk
![[Library] MCI v1.1 - Play/Control media files: post #20](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
I have new problem.
Play a folder.
I'm using:
$^f:: IfWinNotActive, %ScriptName% { Send, {^f} Return } SoundPlay, Nonexistent. FileSelectFolder SelectedFolder, , 3, (*.*) If SelectedFolder = return Else { Loop %SelectedFolder%\*.*,0,1 Soundplay %A_LoopFileFullPath%, WAIT return } ReturnCan you help me with rewrite this to mci?
Mci.ahk is best library for work with auio.
![[Library] MCI v1.1 - Play/Control media files: post #21](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
Dunno why it happened, but it wouldn't play certain MP3 files with long names (possibly too long path exceeding Win9x limit). However, same files wouldn't play even when names/paths were shortened below limit. Then, playing other acceptable file and trying the previously shortened one again, it would play fine! :?
So I ended up using fincs' Sound library instead of MCI, which would play the original files (unshortened, unmodified) without problems. :oops:
I've enhanced a little bit the Music Player that uses Sound; will post the script in its thread (provided I find it

![[Library] MCI v1.1 - Play/Control media files: post #22](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
(AHK 1.0.48.05 and Win98SE) forever | My scripts are here
A full answer to this question would require significant detail. The short answer: Load all of the media files from the selected folder into a list, a "playlist" if you will, and then play each media file one at a time. You need to open each file with the MCI_Open function and play each file using the MCI_Play function using the "Callback" option to notify you when a media file has finished playing.I have new problem.
Play a folder.
I'm using:;{Snip} SoundPlay, Nonexistent. FileSelectFolder SelectedFolder, , 3, (*.*) If SelectedFolder = return Else { Loop %SelectedFolder%\*.*,0,1 Soundplay %A_LoopFileFullPath%, WAIT return } ReturnCan you help me with rewrite this to mci?
The following is a working but unfinished (I repeat, unfinished) example of how the Callback feature works:
#NoEnv #SingleInstance Force gui Margin,0,0 gui Add,Button,w60 h25 ,Open gui Add,Button,x+0 wp hp,Play gui Add,Button,x+0 wp hp,Pause gui Add,Button,x+0 wp hp vStop,Stop gui Add ,Slider ,x+0 w160 hp || +Disabled ;-- Start off disabled || +ToolTip || vSlider || gSlider Messages=Notify messages are displayed here. New items added to the top. gui Add ,Edit ,xm w400 h180 || +ReadOnly || vMessages ,%Messages% gui Show gosub ButtonOpen return GUIEscape: GUIClose: if Open MCI_Close(hMedia) ExitApp ButtonOpen: if Open { MCI_Close(hMedia) SetTimer UpdateSlider,off GUIControl,,Slider,0 GUIControl Disable,Slider } if not DefaultFolder DefaultFolder:=A_MyDocuments FileSelectFile MediaFile,1,%DefaultFolder%,Choose a media file if MediaFile= return SplitPath MediaFile,,DefaultFolder hMedia:=MCI_Open(MediaFile) if not hMedia { MsgBox Error opening media file return } Open:=true MediaLength:=MCI_Length(hMedia) ;-- For this example, the length of the media file is collected once on ; open. The value is used by the Slider routines. GUIControl Enable,Slider SetTimer UpdateSlider,1000 gosub ButtonPlay return ButtonPlay: if Open { Status:=MCI_Status(hMedia) if Status=Stopped { Messages:=A_Now . ": Notify set`n" . Messages GUIControl,,Messages,%Messages% MCI_Play(hMedia,"","NotifyEndOfPlay") ;-- Notify is set here } else if Status=Paused MCI_Resume(hMedia) } return ButtonPause: if Open { Status:=MCI_Status(hMedia) if Status=Playing MCI_Pause(hMedia) else if Status=Paused MCI_Resume(hMedia) ;-- Note: Pause and Resume do not interrupt Notify } return ButtonStop: if Open { MCI_Stop(hMedia) MCI_Seek(hMedia,0) } return Slider: if Open { Status:=MCI_Status(hMedia) if Status in Playing,Paused { Messages:=A_Now . ": Notify set/reset`n" . Messages GUIControl,,Messages,%Messages% MCI_Play(hMedia,"from " . floor(MediaLength*(Slider/100)),"NotifyEndOfPlay") ;-- MCI_Seek is not used to reposition the media in this example ; because the function will cause a Notify interruption for most ; devices. ; ; Using the "From" flag, MCI_Play will successfully reposition ; the media for most MCI devices. Calling MCI_Play (with ; callback) while media is playing will abort the original Notify ; condition (if any) but will create a new Notify condition. if Status=Paused MCI_Pause(hMedia) } ;-- Reset focus GUIControl Focus,Stop } return UpdateSlider: if Open { ;-- Only update slider if object is NOT in focus GUIControlGet Control,FocusV if Control<>Slider GUIControl,,Slider,% (MCI_Position(hMedia)/MediaLength)*100 } return NotifyEndOfPlay(Flag) { Global outputdebug Function: %A_ThisFunc% flag=%flag% if Flag=1 MCINotifyValue=MCI_NOTIFY_SUCCESSFUL (1) if Flag=2 MCINotifyValue=MCI_NOTIFY_SUPERSEDED (2) if Flag=4 MCINotifyValue=MCI_NOTIFY_ABORTED (4) if Flag=8 MCINotifyValue=MCI_NOTIFY_FAILURE (8) Messages:=A_Now . ": " . MCINotifyValue . "`n" . Messages GUIControl,,Messages,%Messages% if Flag=1 gosub ButtonStop return } #include MCI.ahkIf you need additional help, PM me and I will try to help you the best I can.
This is the first I've heard of anyone having filename problems with the MCI library/Examples. Unfortunately I don't have access to a Win9x machine anymore (killed my last one about a month ago) so I can't test it in that environment. If you figure out a fix/workaround, let me know and I'll make a fix.I've had some problems with filenames while fiddling with the example MCI player.
Dunno why it happened, but it wouldn't play certain MP3 files with long names (possibly too long path exceeding Win9x limit).
![[Library] MCI v1.1 - Play/Control media files: post #23](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
Thanks for your support and endorsement. I think most serious developers will eventually migrate towards the feature-rich BASS library but the MCI library is small and fairly simply so it is still quite useful. Thanks for introducing it to the forum.Hah, I missed this... :lol:
Well, first congratulations for making a library to replace
my old and deprecated Sound.ahk...
I hope you suceed with this proyect
fincs - the autor of Sound.ahk and Media.ahk

![[Library] MCI v1.1 - Play/Control media files: post #24](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
FileSelectFolder SelectedFolder, , M, (*.*) If SelectedFolder = return Else { Loop %SelectedFolder%\*.mp3,0,1 hMedia:=MCI_Open(a_loopfilefullpath) if not hMedia { MsgBox Error opening media file %A_LoopFileFullPath% return } Open:=true MediaLength:=MCI_Length(hMedia) ;-- For this example, the length of the media file is collected once on ; open. The value is used by the Slider routines. gosub Play } returnCan you help me?
![[Library] MCI v1.1 - Play/Control media files: post #25](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
If I ever get around testing under such conditions and manage to find a pattern (I tried at the time but failed), I'll notify you. But as you said, BASS is the new kid on the block so there's no emergency. I jumped into the Trout boat myself, lately.This is the first I've heard of anyone having filename problems with the MCI library/Examples. Unfortunately I don't have access to a Win9x machine anymore (killed my last one about a month ago) so I can't test it in that environment. If you figure out a fix/workaround, let me know and I'll make a fix.
![[Library] MCI v1.1 - Play/Control media files: post #26](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
(AHK 1.0.48.05 and Win98SE) forever | My scripts are here
Again, short answer. In your example, you are opening every single MP3 file in the selected folder and then checking/playing the last one. The code might be more appropriately written like this. Notice the additional set of brackets.Why player write can't open media file, when I use this?
FileSelectFolder SelectedFolder, , M, (*.*) If SelectedFolder = return Else { Loop %SelectedFolder%\*.mp3,0,1 hMedia:=MCI_Open(a_loopfilefullpath) if not hMedia { MsgBox Error opening media file %A_LoopFileFullPath% return } Open:=true MediaLength:=MCI_Length(hMedia) ;-- For this example, the length of the media file is collected once on ; open. The value is used by the Slider routines. gosub Play } returnCan you help me?
. . . Else { Loop %SelectedFolder%\*.mp3,0,1 { hMedia:=MCI_Open(a_loopfilefullpath) if not hMedia { MsgBox Error opening media file %A_LoopFileFullPath% return } Open:=true MediaLength:=MCI_Length(hMedia) gosub Play MCI_Close(hMedia) } }But and however, this method won't work as expected because the MCI_Play function does not, by default, wait until the media file is finished playing before returning. Please read the entire first post in this thread and the documentation in the MCI library for additional information.
If you have any additional questions on this topic, please PM me. I will try to help you the best I can.
![[Library] MCI v1.1 - Play/Control media files: post #27](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)

![[Library] MCI v1.1 - Play/Control media files: post #28](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
(AHK 1.0.48.05 and Win98SE) forever | My scripts are here
![[Library] MCI v1.1 - Play/Control media files: post #29](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)
Yes, the "wait" flag is not recommended except for very short clips. I noted this in the documentation for the MCI_Play function.When I set wait parameter, and start play, my computer is suspended and I must wai, when player finish play.
![[Library] MCI v1.1 - Play/Control media files: post #30](http://autohotkey.com/board/public/style_images/ortem/icon_share.png)