AutoHotkey Community

It is currently May 26th, 2012, 3:31 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 66 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject:
PostPosted: March 14th, 2009, 10:22 pm 
Offline

Joined: February 19th, 2007, 9:03 am
Posts: 338
Location: Czech Republic
Hi all.
Can you write some setvolume example for %selectedfile%?
I want use this in my player at:
svn://autohotkey.net/vlcekp1/myrepos/player/

_________________
Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2009, 2:43 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2009, 8:37 am 
Offline

Joined: February 19th, 2007, 9:03 am
Posts: 338
Location: Czech Republic
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2009, 3:26 pm 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2009, 3:38 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
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

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2009, 4:44 pm 
Offline

Joined: February 19th, 2007, 9:03 am
Posts: 338
Location: Czech Republic
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2009, 6:50 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
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. :oops:

I've enhanced a little bit the Music Player that uses Sound; will post the script in its thread (provided I find it :D ) - it contains a rudimentary playlist feature.

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2009, 5:22 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2009, 5:38 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
fincs wrote:
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

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. :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2009, 4:49 pm 
Offline

Joined: February 19th, 2007, 9:03 am
Posts: 338
Location: Czech Republic
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2009, 10:25 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
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 (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2009, 2:57 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2009, 10:14 am 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
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 (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2009, 6:20 pm 
Offline

Joined: February 19th, 2007, 9:03 am
Posts: 338
Location: Czech Republic
When I set wait parameter, and start play, my computer is suspended and I must wai, when player finish play.

_________________
Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2009, 11:26 pm 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 66 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, tank and 15 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group