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
Can the Mac version play MP3's
-
- Addict
- Posts: 1309
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Re: Can the Mac version play MP3's
Mac OS Big Sur 11.5.2
Using the movie library to play an MP3 file using the Movie.pb example.
The song plays ok but MovieStatus() does not work it always returns 0?
The code I am using is below.
Using the movie library to play an MP3 file using the Movie.pb example.
The song plays ok but MovieStatus() does not work it always returns 0?
The code I am using is below.
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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Re: Can the Mac version play MP3's
@collectordave,
I didn't know about MoviePlayer, for playing music.
Tried your code and it worked.
Thank you.
I didn't know about MoviePlayer, for playing music.
Tried your code and it worked.
Thank you.
DE AA EB
-
- Addict
- Posts: 1309
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Re: Can the Mac version play MP3's
Hi
Did you get Moviestatus() to work?
Did you get Moviestatus() to work?
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Re: Can the Mac version play MP3's
@collectordave,
I wasn't aware of it when I first ran it yesterday, sorry.
Tried it again today and found it always returns a zero!
MacBook Pro M1
PB 6.00 c-backend
I wasn't aware of it when I first ran it yesterday, sorry.
Tried it again today and found it always returns a zero!
MacBook Pro M1
PB 6.00 c-backend
DE AA EB
Re: Can the Mac version play MP3's
But this is how it should work:
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
-
- Addict
- Posts: 1309
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Re: Can the Mac version play MP3's
Thanks works first time.
Just need to understand it now.
Just need to understand it now.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.