Can the Mac version play MP3's

Mac OSX specific forum
ColBoy
Enthusiast
Enthusiast
Posts: 143
Joined: Fri Feb 13, 2004 2:37 pm
Location: Ottawa, Canada
Contact:

Can the Mac version play MP3's

Post 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
Colin
Fred
Administrator
Administrator
Posts: 14737
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Use PlayMovie() for playing MP3 as it uses QuickTime.
collectordave
Addict
Addict
Posts: 1292
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Can the Mac version play MP3's

Post 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
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.
davido
Addict
Addict
Posts: 1880
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Can the Mac version play MP3's

Post by davido »

@collectordave,

I didn't know about MoviePlayer, for playing music.
Tried your code and it worked.
Thank you. :D
DE AA EB
collectordave
Addict
Addict
Posts: 1292
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Can the Mac version play MP3's

Post by collectordave »

Hi

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.
davido
Addict
Addict
Posts: 1880
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Can the Mac version play MP3's

Post 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
DE AA EB
ccode_new
New User
New User
Posts: 4
Joined: Sat Jul 30, 2022 10:39 am

Re: Can the Mac version play MP3's

Post 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
collectordave
Addict
Addict
Posts: 1292
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Can the Mac version play MP3's

Post by collectordave »

Thanks works first time.

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.
Post Reply