reaching the end of a music file

Just starting out? Need help? Post your questions and find answers here.
jcoggins
User
User
Posts: 25
Joined: Sat Apr 12, 2008 12:30 am

reaching the end of a music file

Post 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
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post 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.
Tranquil
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post 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...
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re:

Post 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?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Re: reaching the end of a music file

Post 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?
PureBasic for Windows
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: reaching the end of a music file

Post 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! :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
KJ67
Enthusiast
Enthusiast
Posts: 218
Joined: Fri Jun 26, 2009 3:51 pm
Location: Westernmost tip of Norway

Re: reaching the end of a music file

Post 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 
The best preparation for tomorrow is doing your best today.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: reaching the end of a music file

Post 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
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
idle
Always Here
Always Here
Posts: 5838
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: reaching the end of a music file

Post 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

Post Reply