 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
vlcek
Joined: 19 Feb 2007 Posts: 338 Location: Czech Republic
|
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 748 Location: Texas, USA
|
Posted: Sun Mar 15, 2009 1:43 am Post subject: |
|
|
| vlcek wrote: | | Can you write some setvolume example for %selectedfile%? |
The code for calling the MCI_SetVolume function is fairly straightforward:
| Code: | 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 device |
Although 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! |
|
| Back to top |
|
 |
vlcek
Joined: 19 Feb 2007 Posts: 338 Location: Czech Republic
|
Posted: Sun Mar 15, 2009 7:37 am Post subject: |
|
|
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. _________________ Thanks. |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 748 Location: Texas, USA
|
Posted: Sun Mar 15, 2009 2:26 pm Post subject: |
|
|
| vlcek wrote: | 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. |
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.
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! |
|
| Back to top |
|
 |
fincs
Joined: 05 May 2007 Posts: 1163 Location: Seville, Spain
|
Posted: Sun Mar 15, 2009 2:38 pm Post subject: |
|
|
Hah, I missed this...
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 _________________ fincs
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list] |
|
| Back to top |
|
 |
vlcek
Joined: 19 Feb 2007 Posts: 338 Location: Czech Republic
|
Posted: Sun Mar 15, 2009 3:44 pm Post subject: |
|
|
My friend downloaded the player from the svn and created function for ini read and ini write.
I have new problem.
Play a folder.
I'm using:
| Code: |
$^f::
IfWinNotActive, %ScriptName%
{
Send, {^f}
Return
}
SoundPlay, Nonexistent.
FileSelectFolder SelectedFolder, , 3, (*.*)
If SelectedFolder =
return
Else
{
Loop %SelectedFolder%\*.*,0,1
Soundplay %A_LoopFileFullPath%, WAIT
return
}
Return
|
Can you help me with rewrite this to mci?
Mci.ahk is best library for work with auio. _________________ Thanks. |
|
| Back to top |
|
 |
Drugwash
Joined: 07 Sep 2008 Posts: 921 Location: Ploiesti, RO
|
Posted: Sun Mar 15, 2009 5:50 pm Post subject: |
|
|
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). 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.
I've enhanced a little bit the Music Player that uses Sound; will post the script in its thread (provided I find it ) - it contains a rudimentary playlist feature. _________________ AHK tools by Drugwash |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 748 Location: Texas, USA
|
Posted: Mon Mar 16, 2009 4:22 am Post subject: |
|
|
| vlcek wrote: | I have new problem.
Play a folder.
I'm using:
| Code: | ;{Snip}
SoundPlay, Nonexistent.
FileSelectFolder SelectedFolder, , 3, (*.*)
If SelectedFolder =
return
Else
{
Loop %SelectedFolder%\*.*,0,1
Soundplay %A_LoopFileFullPath%, WAIT
return
}
Return
|
Can you help me with rewrite this to mci?
|
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.
The following is a working but unfinished (I repeat, unfinished) example of how the Callback feature works:
| Code: | #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.ahk
|
If you need additional help, PM me and I will try to help you the best I can.
| Drugwash wrote: | 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).
|
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. |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 748 Location: Texas, USA
|
Posted: Mon Mar 16, 2009 4:38 am Post subject: |
|
|
| fincs wrote: | Hah, I missed this...
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 |
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.  |
|
| Back to top |
|
 |
vlcek
Joined: 19 Feb 2007 Posts: 338 Location: Czech Republic
|
Posted: Mon Mar 16, 2009 3:49 pm Post subject: |
|
|
Why player write can't open media file, when I use this?
| Code: |
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
}
return
|
Can you help me? _________________ Thanks. |
|
| Back to top |
|
 |
Drugwash
Joined: 07 Sep 2008 Posts: 921 Location: Ploiesti, RO
|
Posted: Mon Mar 16, 2009 9:25 pm Post subject: |
|
|
| jballi wrote: | | 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. | 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. _________________ AHK tools by Drugwash |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 748 Location: Texas, USA
|
Posted: Tue Mar 17, 2009 1:57 am Post subject: |
|
|
| vlcek wrote: | Why player write can't open media file, when I use this?
| Code: | 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
}
return
|
Can you help me? |
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.
| Code: | .
.
.
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. |
|
| Back to top |
|
 |
Drugwash
Joined: 07 Sep 2008 Posts: 921 Location: Ploiesti, RO
|
Posted: Tue Mar 17, 2009 9:14 am Post subject: |
|
|
You know, I mentioned my enhanced player earlier in this thread - albeit it's using Sound, not MCI - for a reason. I believe the playlist feature may be ported fairly easily, or at least I hope so. _________________ AHK tools by Drugwash |
|
| Back to top |
|
 |
vlcek
Joined: 19 Feb 2007 Posts: 338 Location: Czech Republic
|
Posted: Tue Mar 17, 2009 5:20 pm Post subject: |
|
|
When I set wait parameter, and start play, my computer is suspended and I must wai, when player finish play. _________________ Thanks. |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 748 Location: Texas, USA
|
Posted: Tue Mar 17, 2009 10:26 pm Post subject: |
|
|
| vlcek wrote: | | When I set wait parameter, and start play, my computer is suspended and I must wai, when player finish play. |
Yes, the "wait" flag is not recommended except for very short clips. I noted this in the documentation for the MCI_Play function. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|