Page 1 of 1

Can the Mac version play MP3's

Posted: Thu Jul 21, 2005 4:18 am
by ColBoy
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

Posted: Thu Jul 21, 2005 11:11 am
by Fred
Use PlayMovie() for playing MP3 as it uses QuickTime.

Re: Can the Mac version play MP3's

Posted: Sun Jul 31, 2022 8:52 am
by collectordave
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.

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

Re: Can the Mac version play MP3's

Posted: Sun Jul 31, 2022 6:58 pm
by davido
@collectordave,

I didn't know about MoviePlayer, for playing music.
Tried your code and it worked.
Thank you. :D

Re: Can the Mac version play MP3's

Posted: Mon Aug 01, 2022 8:55 am
by collectordave
Hi

Did you get Moviestatus() to work?

Re: Can the Mac version play MP3's

Posted: Mon Aug 01, 2022 7:04 pm
by davido
@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

Re: Can the Mac version play MP3's

Posted: Mon Aug 01, 2022 7:32 pm
by ccode_new
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

Re: Can the Mac version play MP3's

Posted: Tue Aug 02, 2022 7:32 am
by collectordave
Thanks works first time.

Just need to understand it now.