AutoHotkey Community

It is currently May 27th, 2012, 1:23 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 66 posts ]  Go to page Previous  1, 2, 3, 4, 5
Author Message
 Post subject:
PostPosted: March 23rd, 2011, 12:03 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
webster14 wrote:
The function for the lenght of a media file gives me a longer time that the actual file has

The "problem" appears to be limited to variable bitrate (VBR) MP3s. I noted this error a very long time ago on another thread.

webster14 wrote:
when I play a file sometimes it plays 2 or 3 times to fill the time that the function for length gives. Is it a function problem, a dll problem or an encoding one?


Although the MCI_Length function returns a value that is larger that the actual length, it does not (read: should not) affect playback.

If you haven't done it already, try to play your media using the sample scripts that are provided with this project. Many of the scripts will play most media types, including VBR MP3s.

Good luck!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2011, 4:01 am 
Offline

Joined: June 25th, 2010, 4:20 pm
Posts: 11
Hey, is it possible to make sound loop?
If so how?

_________________
Ain't no rest for the wicked. Money don't grow on trees.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2011, 6:57 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
[HTT]CantTouchMe wrote:
Hey, is it possible to make sound loop?
If so how?

Here's one way to do it. For the MCI_Play function, include from and to flags in the p_Flags parameter and specify a callback function name in the p_Callback parameter.

In the following example, the script will loop any media file from 25000 to 35000 (from 25 seconds to 35 seconds) until the Stop button is pressed. To loop the entire media file just get rid of the from and to flags.

Code:
#NoEnv
#SingleInstance Force

gui Margin,0,0
gui Add,Button,w70 h35,Open
gui Add,Button,x+0 wp hp,Play
gui Add,Button,x+0 wp hp,Pause
gui Add,Button,x+0 wp hp,Stop
gui Show

gosub ButtonOpen
return


GUIEscape:
GUIClose:
if Open
    MCI_Close(hMedia)

ExitApp


ButtonOpen:
if Open
    MCI_Close(hMedia)

if not DefaultFolder
    DefaultFolder:=A_MyDocuments

gui +OwnDialogs
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
gosub ButtonPlay
return


ButtonPlay:
if Open
    {
    Status:=MCI_Status(hMedia)
    if (Status="Stopped")
        gosub Play
     else
        if (Status="Paused")
            MCI_Resume(hMedia)
    }

return

Play:
MCI_Play(hMedia,"from 25000 to 35000","NotifyEndOfPlay")
return


ButtonPause:
if Open
    {
    Status:=MCI_Status(hMedia)
    if (Status="Playing")
        MCI_Pause(hMedia)
     else
        if (Status="Paused")
            MCI_Resume(hMedia)
    }

return


ButtonStop:
if Open
    {
    MCI_Stop(hMedia)
    MCI_Seek(hMedia,0)
    }

return


NotifyEndOfPlay(Flag)
    {
    Global
;;;;;    Critical
    if (Flag=1)  ;-- 1=play ended normally
        gosub Play
    }


#include MCI.ahk

The only problem that I ran into is that callback routine gets lost (returns a to-be-determined value) if the loop period is too short (less than 3 or 4 seconds?). Reliability can be improved by adding a Critical statement to the callback function.

I hope this helps.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 27th, 2011, 2:15 am 
Offline

Joined: June 25th, 2010, 4:20 pm
Posts: 11
Thanks it works but
jballi wrote:
In the following example, the script will loop any media file from 25000 to 35000 (from 25 seconds to 35 seconds) until the Stop button is pressed. To loop the entire media file just get rid of the from and to flags.

I took the "from 25000 to 35000" part off and it won't loop. Even tested it on the one example you gave here.
Well the workaround I did was added "from 0 to 27000" which is the start until the end of the music.

Cheers

_________________
Ain't no rest for the wicked. Money don't grow on trees.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 27th, 2011, 5:56 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
[HTT]CantTouchMe wrote:
I took the "from 25000 to 35000" part off and it won't loop. Even tested it on the one example you gave here.
Well the workaround I did was added "from 0 to 27000" which is the start until the end of the music.

I'm glad you figured it out. The "from 25000 to 35000" flags were just an example. It makes sense that it didn't work if the track ended at 27000. As I mentioned earlier, you don't need the from and to flags if you want to play the entire media file.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 23rd, 2012, 10:59 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
v1.1
Minor changes to support Unicode. See the bottom of the first post for more information.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon and 12 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