Page 1 of 1

reaching the end of a music file

Posted: Sat Apr 19, 2008 7:48 pm
by jcoggins
Is there any way for a program to know when it has reached the end of an audio file (with no picture frames)?

Jason

Posted: Sun Apr 20, 2008 2:31 am
by Tranquil
if you know the exact playtime of you track then just count it on your own.
Maybe you want to use an mp3 file to playback you can find a code snipped here on that forum to calculate the playtime.

EDIT:
Maybe you can also use MovieStatus() but I have not tried it yet.

Posted: Sun Apr 20, 2008 3:36 am
by Rook Zimbabwe
I don't think moviestatus will do it:
Note: Be careful with this function when using sounds (e.g. MP3) as no pictures (frames) exist.
This might have to be done from the API in windows...

Re:

Posted: Sun Aug 08, 2010 11:08 am
by PB
> if you know the exact playtime of you track then just count it on your own

Interesting. Does anyone know how to tell the play length of an MP3 file?

Re: reaching the end of a music file

Posted: Sun Aug 08, 2010 12:16 pm
by Marco2007
@PB: I`ver tried several mp3-Files and MovieStatus seems to work now -> returns 0, when the song has ended...tried about 20 mp3-Files...from 2min up to 10min...Can you upload one, where it doesn`t work?

Re: reaching the end of a music file

Posted: Sun Aug 08, 2010 1:43 pm
by PB
@Marco2007: Actually, you're right, it's working for me now. :shock:

Maybe I coded something wrong before, because I was definitely
not getting a correct result with my last attempt. Thanks! :)

Re: reaching the end of a music file

Posted: Sun Aug 08, 2010 2:13 pm
by KJ67
Are you sure it works?
I had some problems earlier on when I played with the examples.

Uncomment the delay and this works for me, but not without some startup-delay.

Code: Select all

If InitMovie() = 0
  MessageRequester("Error", "Can't initialize movie playback !", 0) 
  End
EndIf

MovieName$ = OpenFileRequester("Choose the movie to play", "", "Movie/Audio files|*.avi;*.mpg;*.asf;*.mp3;*.wav|All Files|*.*", 0)
If MovieName$
  If LoadMovie(0, MovieName$)
    
    OpenWindow(0, 100, 150, MovieWidth(0), MovieHeight(0), "PureBasic - Movie")
    PlayMovie(0, WindowID(0))
    ;Delay(500)
    Repeat
      If MovieStatus(0)=0
        MessageRequester("Done?","")
        End
      EndIf
      
    Until WaitWindowEvent() = #PB_Event_CloseWindow
  Else
    MessageRequester("Error", "Can't load the movie...", 0)
  EndIf
EndIf 

Re: reaching the end of a music file

Posted: Sun Aug 08, 2010 2:38 pm
by PB
KJ67, I see what you mean. Here's my workaround for you.
It plays the MP3 until it finishes or you close the window.
Note the While/Wend instead of Delay(500) -- it's faster.

Code: Select all

m$="D:\[Media]\Music\Darryl McDowell - Soul Glo.mp3"

If OpenWindow(0,200,200,200,100,"test",#PB_Window_SystemMenu)
  TextGadget(0,10,10,100,20,"")
  InitMovie() : LoadMovie(0,m$) : PlayMovie(0,WindowID(0))
  While MovieStatus(0)=0 : Wend ; Let the movie start! :)
  Repeat
    s=MovieStatus(0) : SetGadgetText(0,Str(s))
  Until s=0 Or WaitWindowEvent(1)=#PB_Event_CloseWindow
EndIf

Re: reaching the end of a music file

Posted: Sun Aug 08, 2010 10:25 pm
by idle
load file names into a list and then you can process through them like this

Code: Select all

If Not IsMovie(0)
  If Not NextElement(queue())
    FirstElement(queue())
  EndIf
  If LoadMovie(0,queue())
     PlayMovie(0,hwnd)
     Delay(100) ;need a delay or movie status may return not playing
    ;or like pb said a while loop 
    ;while not moviestatus(0)
    ;  delay(0)  ;let the cpu context change nicely
    ;wend  
  Else
     DeleteElement(queue())
  EndIf
ElseIf Not MovieStatus(0)
  DeleteElement(queue())
  FreeMovie(0)
EndIf