Page 1 of 1

MovieStatus not working on version 6.21

Posted: Sat Aug 02, 2025 7:10 pm
by RoseWilliam
This code works on version 6.20 but not on 6.21
Any ideas
You will have to upload your own music track into the Music folder
Code:-
EnableExplicit
Enumeration
#Media
EndEnumeration

Define FileName$
Define Result
Define Track$="Music\sherry.mp3"; change to your own music

Result=InitMovie()
Debug "Init "+result

FileName$=Track$
Result=LoadMovie(#Media,FileName$)
Debug "Movie Loaded "+result

Debug "Is movie "+ IsMovie(#Media)

Debug "Music Chosen "+FileName$

MessageRequester("Music Info","Continue")

PlayMovie(#Media,#Null)

Delay(2000)

Repeat
Debug MovieStatus(#Media)
If MovieStatus(#Media)<>0
;
Else
Debug "Music finished"
Break
EndIf
ForEver
End

Re: MovieStatus not working on version 6.21

Posted: Sat Aug 02, 2025 8:40 pm
by infratec
Yes, you are right.

Since 6.21 also midi playback is not longer possible. So something changed.

MP3 is still possible, but you need a window and an event loop.
And the result of MovieStatus() is very static, but you can detect the end.

Code: Select all

EnableExplicit

Enumeration
  #Media
EndEnumeration

Define FileName$
Define Result, Flag
Define Status.q


Result = InitMovie()
Debug "Init " + Str(Result)

FileName$ = OpenFileRequester("Choose a MP3 file", "", "All|*.*", 1)
If FileName$
  Result = LoadMovie(#Media, FileName$)
  Debug "Movie Loaded " + Str(Result)
  
  Debug "Is movie "+ IsMovie(#Media)
  
  Debug "Music Chosen " + FileName$
  
  MessageRequester("Music Info", "Continue")
  
  OpenWindow(0, 0, 0, 1, 1, "", #PB_Window_Invisible)
  
  Result = PlayMovie(#Media, WindowID(0))
  Debug "PlayMovie: " + Str(Result)
  
  Repeat
    WaitWindowEvent(10)
    
    Status = MovieStatus(#Media)
    If Not Flag
      Debug "1: " + Status
      If Status <> 0
        Flag = #True
      EndIf
    Else
      Debug "2: " + Status
      If Status = 0
        Debug "Music finished"
        Break
      EndIf
    EndIf
    
  ForEver
  
  CloseWindow(0)
  
EndIf

Re: MovieStatus not working on version 6.21

Posted: Sun Aug 03, 2025 12:37 am
by minimy
Hello, yes, how say infratec, no midi now, but play videos better :mrgreen:

I have this code, but to be honest, I don't remember if it's mine or if I got it from the Internet. It's old, but it works well.
To play music from Windows, I use the API directly. Maybe this will help you.
Tested on Windows 7, 8, 10 and 11. In one zx spectrum too... :lol:

Code: Select all

;------------PLAY MP3 WINDOWS API
DeclareModule MP3
  Enumeration 0 
    #MP3_Error 
    #MP3_Stopped 
    #MP3_Playing 
    #MP3_Paused 
  EndEnumeration
  
  Declare GetStatus(ID)
  Declare Load(ID,file.s) 
  Declare Play(ID) 
  Declare PlayBegin(ID) 
  Declare PlayFromTo(ID,Start,endPos) 
  Declare Pause(ID)
  Declare Resume(ID) 
  Declare Stop(ID) 
  Declare Free(ID) 
  Declare SetVolume(ID,volume) 
  Declare GetVolume(ID) 
  Declare SetSpeed(ID,Tempo) 
  Declare GetSpeed(ID) 
  Declare GetLength(ID) 
  Declare GetPosition(ID) 
  Declare Seek(ID,pos=0) 
  Declare.s TimeToString(Time)  
EndDeclareModule

Module MP3
  Procedure GetStatus(ID)
    Result=#MP3_Error 
    Protected.s a=Space(#MAX_PATH) 
    Protected   rID=mciSendString_("status MP3_"+Str(ID)+" mode",@a,#MAX_PATH,0) 
    If rID=0 
      Select a 
        Case "stopped":Result=#MP3_Stopped 
        Case "playing":Result=#MP3_Playing 
        Case "paused":Result=#MP3_Paused 
      EndSelect 
    EndIf 
    ProcedureReturn Result 
  EndProcedure 
  Procedure Load(ID,file.s) 
    Protected   rID=mciSendString_("OPEN "+Chr(34)+file+Chr(34)+" Type MPEGVIDEO ALIAS MP3_"+Str(ID),0,0,0) 
    If rID=0 
      ProcedureReturn #True
    Else 
      ProcedureReturn #False 
    EndIf 
  EndProcedure 
  Procedure Play(ID) 
    Protected   rID=mciSendString_("play MP3_"+Str(ID),0,0,0) 
    ProcedureReturn rID
  EndProcedure 
  Procedure PlayBegin(ID) 
    Protected   rID=mciSendString_("play MP3_"+Str(ID)+" from "+Str(0),0,0,0) 
    ProcedureReturn rID
  EndProcedure 
  Procedure PlayFromTo(ID,Start,endPos) 
    Protected   rID=mciSendString_("play MP3_"+Str(ID)+" from "+Str(Start)+" to "+Str(endPos),0,0,0) 
    ProcedureReturn rID
  EndProcedure 
  Procedure Pause(ID) 
    Protected   rID=mciSendString_("pause MP3_"+Str(ID),0,0,0) 
    ProcedureReturn rID
  EndProcedure 
  Procedure Resume(ID) 
    Protected   rID=mciSendString_("resume MP3_"+Str(ID),0,0,0) 
    ProcedureReturn rID
  EndProcedure 
  Procedure Stop(ID) 
    Protected   rID=mciSendString_("stop MP3_"+Str(ID),0,0,0) 
    ProcedureReturn rID
  EndProcedure 
  Procedure Free(ID) 
    Protected   rID=mciSendString_("close MP3_"+Str(ID),0,0,0) 
    ProcedureReturn rID
  EndProcedure 
  Procedure SetVolume(ID,volume) 
    ;volumen 0 a 1000
    Protected   rID=mciSendString_("SetAudio MP3_"+Str(ID)+" volume to "+Str(volume),0,0,0) 
    ProcedureReturn rID
  EndProcedure 
  Procedure GetVolume(ID) 
    ;volumen 0 a 1000
    Protected.s a=Space(#MAX_PATH) 
    Protected   rID=mciSendString_("status MP3_"+Str(ID)+" volume",@a,#MAX_PATH,0) 
    ProcedureReturn Val(a) 
  EndProcedure 
  Procedure SetSpeed(ID,Tempo) 
    Protected   rID=mciSendString_("set MP3_"+Str(ID)+" Speed "+Str(Tempo),0,0,0) 
    ProcedureReturn rID
  EndProcedure 
  Procedure GetSpeed(ID) 
    Protected.s a=Space(#MAX_PATH) 
    Protected   rID=mciSendString_("status MP3_"+Str(ID)+" Speed",@a,#MAX_PATH,0) 
    ProcedureReturn Val(a) 
  EndProcedure 
  Procedure GetLength(ID) 
    Protected.s a=Space(#MAX_PATH) 
    Protected   rID=mciSendString_("status MP3_"+Str(ID)+" length",@a,#MAX_PATH,0) 
    ProcedureReturn Val(a) 
  EndProcedure 
  Procedure GetPosition(ID) 
    Protected.s a=Space(#MAX_PATH) 
    Protected   rID=mciSendString_("status MP3_"+Str(ID)+" position",@a,#MAX_PATH,0) 
    ProcedureReturn Val(a) 
  EndProcedure 
  Procedure Seek(ID,pos=0) 
    Protected   rID=mciSendString_("Seek MP3_"+Str(ID)+" to "+Str(pos), 0,0,0) 
    ProcedureReturn rID
  EndProcedure 
  Procedure.s TimeToString(Time) 
    Protected   seg,min
    Time * 0.001
    seg=Time%60:Time/60 
    min=Time%60:Time/60 
    ProcedureReturn RSet(Str(Time),2,"0")+":"+RSet(Str(min),2,"0")+":"+RSet(Str(seg),2,"0") 
  EndProcedure 
EndModule 

CompilerIf #PB_Compiler_IsMainFile
  MP3::Load(0,"melodia4.mp3")
  MP3::Play(0)
  MP3::SetVolume(0,65535)
  Delay(5000)
CompilerEndIf

Re: MovieStatus not working on version 6.21

Posted: Sun Aug 03, 2025 9:35 am
by Piero
Fred said 6.21 now uses Media Foundation instead of the deprecated DirectShow API
https://learn.microsoft.com/en-us/windo ... dation-sdk

You may need to re-encode some of your old media (sometimes even to the same format)
https://learn.microsoft.com/en-us/windo ... foundation
but that's easy and fast with ffmpeg ( ffmpeg.exe -i yourVideo.mp4 yourVideoCOPY.mp4 )

PS: can you win gurus tell me if this can/would help in PB for MIDI etc.?
https://github.com/naudio
Is using .NET libraries possible/convenient in PB? I only found 2003 stuff here: viewtopic.php?t=8941

Re: MovieStatus not working on version 6.21

Posted: Sun Aug 03, 2025 10:04 am
by infratec
PB uses also libmodplug this lib can also play midi.
And Media Foundation can play mp3.

So Fred has new work to do:
Bugfix for mp3 and find a way to play midi again.

Maybe a switch to libopenmpt is the better way, since libmodplug is legacy since 2014.

Re: MovieStatus not working on version 6.21

Posted: Sun Aug 03, 2025 11:09 am
by RoseWilliam
Thanks everyone for your time. At least I now know I am not going crazy.

Re: MovieStatus not working on version 6.21

Posted: Sun Aug 03, 2025 11:43 am
by Piero
This seems to be the cutting-edge win MIDI thing:

https://github.com/microsoft/midi

Re: MovieStatus not working on version 6.21

Posted: Sun Aug 03, 2025 1:16 pm
by Quin
infratec wrote: Sun Aug 03, 2025 10:04 am Maybe a switch to libopenmpt is the better way, since libmodplug is legacy since 2014.
Already suggested here, just seemingly no one cared.

Re: MovieStatus not working on version 6.21

Posted: Sun Aug 03, 2025 3:00 pm
by infratec
I just subscribed :mrgreen:

Re: MovieStatus not working on version 6.21

Posted: Sun Aug 03, 2025 3:51 pm
by minimy
Quin, one more for your army :lol: