Using GetStatus() with a PB loaded sound?

Everything else that doesn't fall into one of the other PB categories.
matthew180
User
User
Posts: 64
Joined: Mon Jun 30, 2003 5:36 pm
Location: Michigan
Contact:

Using GetStatus() with a PB loaded sound?

Post by matthew180 »

Greetings,

Can anyone tell me how I can access the directX sound functions on a sound loaded with PB LoadSound()? I'd really like to know when a sound has finished playing, and DirectSound provides a GetStatus function for each buffer that will, amoung other things, tell you if the sound is still playing.

It sure would be nice if Fred could add a SoundStatus function (poke poke), but until then is there a way to access that GetStatus function on a PB loaded sound?

Thanks,
Matthew
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: Using GetStatus() with a PB loaded sound?

Post by traumatic »

I don't know about the sound commands but it may be possible with
the movie commands.

Just to get you an idea:

Code: Select all

Structure MovieStruc
  Movie.IGraphBuilder
  MediaControl.IMediaControl
  MediaEvent.IMediaEventEx
  Window.IVideoWindow
  Audio.IBasicAudio
  Video.IBasicVideo
  MediaSeeking.IMediaSeeking
  State.l
EndStructure
  

InitMovie()

*movie.MovieStruc = LoadMovie(0, "D:\WINDOWS\Media\chimes.wav")
*movie\MediaSeeking\GetDuration(@duration.l) ; determine the duration - not necessary here ;)

Debug "Duration: "+Str(duration)

PlayMovie(0, 0)

Repeat
  *movie\MediaEvent\WaitForCompletion(10, @evCode.l)

  Delay(2)
Until evCode = 1

StopMovie()

MessageRequester("", "done!")

End
WaitForCompletion() sets evCode.l to 1, if the FilterGraph finished
rendering all available data. Maybe this helps you.

I can't see any way to access the IDirectSoundBuffer though (in this case,
PlayMovie() uses DirectShow of course)

BTW: Fred, please try this:

Code: Select all

Debug  *movie\MediaEvent\WaitForCompletion(10, @evCode.l)
I get an "PUSH - invalid operand" error.
Good programmers don't comment their code. It was hard to write, should be hard to read.
matthew180
User
User
Posts: 64
Joined: Mon Jun 30, 2003 5:36 pm
Location: Michigan
Contact:

Post by matthew180 »

Very nice! I will certinaly give it a try and post my results here. Thanks for the example!

Matthew
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

I spent some more time thinking about it and while I don't know what you're up to,
maybe this approach suits you better:

Code: Select all

  *movie\MediaEvent\GetEvent(@evCode.l, @param1.l, @param2.l, 0)

  If evCode = #EC_COMPLETE
    Debug "done playing"
  EndIf
  
  *movie\MediaEvent\FreeEventParams(evCode, param1, param2)
(#EC_COMPLETE = $01)

...of course you'd normally check the return-value, ie...

Code: Select all

  If *movie\MediaEvent\GetEvent(@evCode.l, @param1.l, @param2.l, 0) = #S_OK

    If evCode = #EC_COMPLETE
      Debug "done playing"
    EndIf
  
    *movie\MediaEvent\FreeEventParams(evCode, param1, param2)
  EndIf
...but that raises the already mentioned "invalid-operand" error...


Well, I only wanted to give you an idea anyway ;)
Good programmers don't comment their code. It was hard to write, should be hard to read.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Just checked the above code with 3.93b1...
...the bug seems to be fixed now :D
Good programmers don't comment their code. It was hard to write, should be hard to read.
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Can PlayMovie be used to play any type of audio that the user has a codec installed for?
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

As PlayMovie() utilizes DirectShow, I'd say yes.
Good programmers don't comment their code. It was hard to write, should be hard to read.
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

nm, i just tested and i'm pretty sure it can. Too bad it takes up so much ram using the Movie functions though =(

But between the bugs of audiere and MP3 bitrates and a few extra megs of ram, it'll have to be the ram for now in DracMP3.
Post Reply