Can the Mac version play MP3's
Posted: Thu Jul 21, 2005 4:18 am
I've been tinkering with PureBasic on my Mac Mini and was wondering if it's possible to play MP3's. I tried PlaySound, but couldn;t get it to work.
Colin
Colin
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
; ------------------------------------------------------------
;
; PureBasic - Movie example file
;
; (c) Fantaisie Software
;
; ------------------------------------------------------------
;
If InitMovie() = 0
MessageRequester("Error", "Can't initialize movie playback !", 0)
End
EndIf
MovieName$ = OpenFileRequester("Choose the movie to play", "", "Movie files|*.avi;*.mpg|All Files|*.*", 0)
If MovieName$
If LoadMovie(0, MovieName$)
OpenWindow(0, 100, 150, 600, 400, "PureBasic - Movie")
Debug PlayMovie(0, WindowID(0))
Debug MovieStatus(0) ; tried this in main repeat loop as well and used PB any to get a movie number other than zero.
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Else
MessageRequester("Error", "Can't load the movie...", 0)
EndIf
EndIf
Code: Select all
Procedure Sound_Load(FileName.s)
ProcedureReturn CocoaMessage(0,CocoaMessage(0,0,"NSSound alloc"), "initWithContentsOfFile:$", @FileName, "byReference:", #YES)
EndProcedure
Procedure Sound_Catch(*MemoryAddress, Size)
Protected Result.i = CocoaMessage(0, 0, "NSData dataWithBytes:", *MemoryAddress, "length:", Size)
If Result : Result = CocoaMessage(0, CocoaMessage(0, 0, "NSSound alloc"), "initWithData:", Result) : EndIf
ProcedureReturn Result
EndProcedure
Procedure Sound_SetVolume(SoundObject, Volume.f)
CocoaMessage(0, SoundObject, "setVolume:@", @Volume)
EndProcedure
Procedure Sound_Play(SoundObject, Loop = 0)
Protected currentTime.d
CocoaMessage(0, SoundObject, "setLoops:", Loop)
CocoaMessage(0, SoundObject, "setCurrentTime:@", @currentTime)
ProcedureReturn CocoaMessage(0, SoundObject, "play")
EndProcedure
Procedure Sound_Stop(SoundObject)
ProcedureReturn CocoaMessage(0, SoundObject, "stop")
EndProcedure
Procedure Sound_IsPlaying(SoundObject)
ProcedureReturn CocoaMessage(0, SoundObject, "isPlaying")
EndProcedure
Procedure Sound_Release(SoundObject)
CocoaMessage(0, SoundObject, "stop")
CocoaMessage(0, SoundObject, "release")
EndProcedure
Global snd
SoundName$ = OpenFileRequester("Choose the sound to play", "", "All Files|*.*", 0)
If SoundName$
snd = Sound_Load(SoundName$)
If snd
OpenWindow(0, 100, 150, 200, 200, "PureBasic - Sound")
Sound_SetVolume(snd, 0.8)
Sound_Play(snd)
Debug Sound_IsPlaying(snd)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Else
MessageRequester("Error", "Can't load the sound...", 0)
End -1
EndIf
EndIf
Sound_Stop(snd)
End 0