MP3 and OpenScreen

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Tron.

Hey everyone,

I am using OpenScreen(640,480,16, "Test") to utilize the sprite functions, but I would also like to play an MP3 in the background. The PlayMovie(0, WindowID()) command is looking for a window to play on. Is there a way to play MP3's without a WindowID()? Is there a way to use the OpenScreen as the WindowID?

Let me know if you need more information.

Thanks,
Tron

"Honesty is the best policy, but insanity is a much better defense."
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Hi Tron,
I never used PlayMovie, so I have no experience with it.
But if you need PlayMovie to play mp3-sound in the background, and PlayMovie needs a Window, why not make a Window in full Desktop size, with no border and use OpenWindowedScreen?
OpenWindowedScreen can be as big as the Window is and you can choose the resolution of it (it can be less or bigger than the actual desktop resolution).
Hope this helps a little bit.


Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Tron.
But if you need PlayMovie to play mp3-sound in the background, and PlayMovie needs a Window, why not make a Window in full Desktop size, with no border and use OpenWindowedScreen?
OpenWindowedScreen can be as big as the Window is and you can choose the resolution of it (it can be less or bigger than the actual desktop resolution).
Thanks for the input Franco!

My only concern with the OpenWindowedScreen is the speed. I haven't done any testing, but maybe you know from experience. Is OpenWindowedScreen as fast the OpenScreen drawing surface? They seem to both be using DirectX so this may not be an issue.

Hey, you got me thinking when you brought up the OpenWindowedScreen. Through some more trial and error I found out a way to play an MP3 and utilize the OpenScreen function.

The problem I had originally was that I was calling the InitSprite function before the InitMovie function. I also found a way I can make the MP3 window invisible using the #BP_Window_Invisible flag.

Here is some sample code:

{Test MP3 and OpenScreen}
If InitMovie() = 0
MessageRequester("Error", "Can't initialize movie playback !", 0)
End
EndIf

mp3.s = "test.mp3" ;substitute your MP3 file here
If LoadMovie(0, mp3.s)
;Window dimensions don't matter since the window is invisible
OpenWindow(0, 0, 0, 20, 30, #PB_Window_Invisible, "my mp3")
PlayMovie(0, 0)
Else
MessageRequester("Error", "Can't load the movie...", 0)
EndIf

;I just put this in to make sure the window was invisible, you can remove it.
MessageRequester("Pause", "For Affect...", 0)

If InitSprite() = 0 Or InitKeyboard() = 0
MessageRequester("Error", "Can't open DirectX 7 Or later", 0)
End
EndIf

If OpenScreen(640, 480, 32, "Drawing Surface")
image.s = "image.bmp" ;substitute your BMP image.
If LoadSprite(0, image.s, 0)
Repeat
FlipBuffers()
ClearScreen(0,0,0)
DisplaySprite(0, 0, 0)
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
Else
MessageRequester("Error", "Can't load Sprite!", 0)
EndIf
FreeSprite(0)
CloseScreen()
Else
MessageRequester("Error", "Can't open a 640*480 - 32 bit screen !", 0)
EndIf

End

---------------------------------
It seems to be working good, now I just need to do some further testing. Like switching to a different MP3, and so on...

Thanks again,
Tron

"Honesty is the best policy, but insanity is a much better defense."
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Just use ScreenID() intead of WindowID() in the playmovie() command. Should work.

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Tron.
Just use ScreenID() intead of WindowID() in the playmovie() command. Should work.
Thanks Fred! That works great!

After you posted this, I searched in the Help file, but I couldn't find the ScreenID() function. Is it an undocumented function? Or did I just over look it?

Thanks again,
Tron

"Honesty is the best policy, but insanity is a much better defense."
Post Reply