It is currently Wed Jul 17, 2019 3:43 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Little MP3-Player without any DLL (with Volume/Speed-Setting
PostPosted: Sun Nov 09, 2003 6:16 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 6:41 pm
Posts: 1356
Code updated For 5.20+

Also no problems with the PB-Sound-System.

Code:
;Info: MCI-MP3-Commands
Enumeration 0
  #MP3_Unknown
  #MP3_Stopped
  #MP3_Playing
  #MP3_Paused
EndEnumeration
Procedure MP3_GetStatus(Nb)
  Result=#MP3_Unknown
  a$=Space(#MAX_PATH)
  i=mciSendString_("status MP3_"+Str(Nb)+" mode",@a$,#MAX_PATH,0)
  If i=0
    Debug a$
    Select a$
      Case "stopped":Result=#MP3_Stopped
      Case "playing":Result=#MP3_Playing
      Case "paused":Result=#MP3_Paused
    EndSelect
  EndIf
  ProcedureReturn Result
EndProcedure
Procedure MP3_Load(Nb,file.s)
  ;i=mciSendString_("open Sequencer!"+Chr(34)+file+Chr(34)+" alias mid"+Str(Nb),0,0,0)
  i=mciSendString_("OPEN "+Chr(34)+file+Chr(34)+" Type MPEGVIDEO ALIAS MP3_"+Str(Nb),0,0,0)
  If i=0
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf
EndProcedure
Procedure MP3_Play(Nb)
  i=mciSendString_("play MP3_"+Str(Nb),0,0,0)
  ProcedureReturn i
EndProcedure
Procedure MP3_PlayStart(Nb)
  i=mciSendString_("play MP3_"+Str(Nb)+" from "+Str(0),0,0,0)
  ProcedureReturn i
EndProcedure
Procedure MP3_PlayPart(Nb,Start,endPos)
  i=mciSendString_("play MP3_"+Str(Nb)+" from "+Str(Start)+" to "+Str(endPos),0,0,0)
  ProcedureReturn i
EndProcedure
Procedure MP3_Pause(Nb)
  i=mciSendString_("pause MP3_"+Str(Nb),0,0,0)
  ProcedureReturn i
EndProcedure
Procedure MP3_Resume(Nb)
  i=mciSendString_("resume MP3_"+Str(Nb),0,0,0)
  ProcedureReturn i
EndProcedure
Procedure MP3_Stop(Nb)
  i=mciSendString_("stop MP3_"+Str(Nb),0,0,0)
  ProcedureReturn i
EndProcedure
Procedure MP3_Free(Nb)
  i=mciSendString_("close MP3_"+Str(Nb),0,0,0)
  ProcedureReturn i
EndProcedure
Procedure MP3_SetVolume(Nb,volume)
  i=mciSendString_("SetAudio MP3_"+Str(Nb)+" volume to "+Str(volume),0,0,0)
  ProcedureReturn i
EndProcedure
Procedure MP3_GetVolume(Nb)
  a$=Space(#MAX_PATH)
  i=mciSendString_("status MP3_"+Str(Nb)+" volume",@a$,#MAX_PATH,0)
  ProcedureReturn Val(a$)
EndProcedure


Procedure MP3_SetSpeed(Nb,Tempo)
  i=mciSendString_("set MP3_"+Str(Nb)+" Speed "+Str(Tempo),0,0,0)
  ProcedureReturn i
EndProcedure
Procedure MP3_GetSpeed(Nb)
  a$=Space(#MAX_PATH)
  i=mciSendString_("status MP3_"+Str(Nb)+" Speed",@a$,#MAX_PATH,0)
  ProcedureReturn Val(a$)
EndProcedure
Procedure MP3_GetLength(Nb)
  a$=Space(#MAX_PATH)
  i=mciSendString_("status MP3_"+Str(Nb)+" length",@a$,#MAX_PATH,0)
  ProcedureReturn Val(a$)
EndProcedure
Procedure MP3_GetPosition(Nb)
  a$=Space(#MAX_PATH)
  i=mciSendString_("status MP3_"+Str(Nb)+" position",@a$,#MAX_PATH,0)
  ProcedureReturn Val(a$)
EndProcedure
Procedure MP3_Seek(Nb,pos)
  i=mciSendString_("Seek MP3_"+Str(Nb)+" to "+Str(pos),0,0,0)
  ProcedureReturn i
EndProcedure
Procedure.s MP3_TimeString(Time)
  Time/1000
  sek=Time%60:Time/60
  min=Time%60:Time/60
  ProcedureReturn RSet(Str(Time),2,"0")+":"+RSet(Str(min),2,"0")+":"+RSet(Str(sek),2,"0")
EndProcedure
;Example

Enumeration 1
  #gadget_File
  #Gadget_VolumeTxt
  #Gadget_Volume
  #Gadget_SpeedTxt
  #Gadget_Speed
  #Gadget_PositionTxt
  #Gadget_Position
  #Gadget_Load
  #Gadget_Play
  #Gadget_Stop
  #Gadget_Pause
  #Gadget_Resume
EndEnumeration

Procedure SetVol(x)
  SetGadgetText(#Gadget_VolumeTxt,"Volume:"+Str(x))
  SetGadgetState(#Gadget_Volume,x)
EndProcedure
Procedure SetSpeed(x)
  SetGadgetText(#Gadget_SpeedTxt,"Speed:"+Str(x))
  SetGadgetState(#Gadget_Speed,x)
EndProcedure
Procedure SetPosition(x,max)
  SetGadgetText(#Gadget_PositionTxt,"Position:"+MP3_TimeString(x)+" : "+MP3_TimeString(max))
  If max>0
    SetGadgetState(#Gadget_Position,x*1000/max)
  Else
    SetGadgetState(#Gadget_Position,0)
  EndIf
EndProcedure

If OpenWindow(0, 100, 200, 310,310, "Simple MP3-Player", #PB_Window_SystemMenu |#PB_Window_ScreenCentered)
  ;       If CreateGadgetList(WindowID())
  top=5
  TextGadget    (#gadget_File       ,5,top,300,20,"File:"):top+25
  TextGadget    (#Gadget_VolumeTxt,  5,top,300,20,"Volume"):top+20
  TrackBarGadget(#Gadget_Volume     ,5,top,300,25,0,100):top+30
  TextGadget    (#Gadget_SpeedTxt   ,5,top,300,20,"Speed"):top+20
  TrackBarGadget(#Gadget_Speed      ,5,top,300,25,0,200):top+30
  TextGadget    (#Gadget_PositionTxt,5,top,300,20,"Position"):top+20
  TrackBarGadget(#Gadget_Position   ,5,top,300,25,0,1000):top+30
  ButtonGadget  (#Gadget_Load       ,5,top,300,20,"Load"):top+25
  ButtonGadget  (#Gadget_Play       ,5,top,300,20,"Play"):top+25
  ButtonGadget  (#Gadget_Pause      ,5,top,300,20,"Pause"):top+25
  ButtonGadget  (#Gadget_Resume     ,5,top,300,20,"Resume"):top+25
  ButtonGadget  (#Gadget_Stop       ,5,top,300,20,"Stop"):top+25
  loaded=#False
  Quit=#False
 
  Repeat
    EventID = WindowEvent()
   
    Select EventID
      Case 0
        If loaded And max>0
          x=MP3_GetPosition(1)
          If GetGadgetState(#Gadget_Position)<>x*1000/max
            SetPosition(x,max)
          EndIf
        EndIf
        Delay(100)
      Case #PB_Event_CloseWindow ; If the user has pressed on the close button
        Quit=#True
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Gadget_Load
            File$=OpenFileRequester("","","Media (Wave,MP3,OGG)|*.wav;*.ogg;*.mp3|Wave|*.wav|mp3|*.mp3|OGG|*.OGG|ALL|*.*",0)
            If File$<>""
              If loaded
                MP3_Free(1)
                loaded=#False
              EndIf
              If MP3_Load(1,File$)
                max=MP3_GetLength(1)
                SetVol(MP3_GetVolume(1)/10)
                SetSpeed(MP3_GetSpeed(1)/10)
                SetPosition(0,max)
                loaded=#True
                SetGadgetText(#gadget_File,"File:"+File$)
              Else
                SetGadgetText(#gadget_File,"File")
              EndIf
            EndIf
          Case #Gadget_Resume
            If loaded
              MP3_Resume(1)
            EndIf
          Case #Gadget_Pause
            If loaded
              MP3_Pause(1)
            EndIf
          Case #Gadget_Play
            If loaded
              MP3_Play(1)
            EndIf
          Case #Gadget_Stop
            If loaded
              MP3_Stop(1)
            EndIf
          Case #Gadget_Position
            If loaded And max>0
              x=GetGadgetState(#Gadget_Position)*max/1000
              SetPosition(x,max)
              MP3_Seek(1,x)
              MP3_Resume(1)
            EndIf
          Case #Gadget_Volume
            If loaded
              x=GetGadgetState(#Gadget_Volume)
              SetVol(x)
              MP3_SetVolume(1,x*10)
            EndIf
          Case #Gadget_Speed
            If loaded
              x=GetGadgetState(#Gadget_Speed)
              SetSpeed(x)
              MP3_SetSpeed(1,x*10)
            EndIf
        EndSelect
    EndSelect
   
  Until Quit
  If loaded
    MP3_Stop(1)
    MP3_Free(1)
  EndIf
  ;       EndIf
EndIf

End


Thanks to cnesm for his basic idea.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Nov 09, 2003 7:37 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Apr 26, 2003 3:23 pm
Posts: 263
Good stuff -- I didn't even know the MDI commands could handle MP3s!

_________________
James Boyd
http://www.hi-toro.com/
Death to the Pixies!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Nov 09, 2003 7:58 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 6:41 pm
Posts: 1356
And midis, and WMA, and (when you install a codec) Ogg.

It seems, that the device MPEGVIDEO is a warper to the mediaplayer...


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Nov 09, 2003 11:08 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Apr 29, 2003 9:18 pm
Posts: 1459
Location: North by Northwest
Thanks for the code.
There is a little bug (well at least I think it is one...):
when you set the speed to 0 the music doesn't stop it runs on normal (100) speed. At 1 it acts at it should.
Maybe it's intention, but I thought I let you know :)

Anyway, didn't know you could change the speed of MP3.

I remember when Dire Straits where a new band they had a maxi single with "Twisting by the pool" and instead of 45rpm I played it at 33rpm 8)

_________________

I am to provide the public with beneficial shocks.
Alfred Hitshock


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Nov 10, 2003 8:53 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 7:52 pm
Posts: 124
Location: Netherlands
Nice routines,

Is it possible to change the soundfrequency.

e.g. I want to play at 50% speed, but then with pitch at original tone.

Thus, playing without changing the pitch

_________________
Cor de Visser

Registered PureBasic user

Author of ChordPlanet
Made with PureBasic
http://www.chordplanet.com


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 11, 2003 6:16 pm 
Offline
User
User

Joined: Sat Jun 21, 2003 11:15 pm
Posts: 54
Hi,

Quote:
Thanks to cnesm for his basic idea.


No problem, man :D

But your code is better than mine :)

_________________
http://cnesm.de.vu


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 11, 2003 6:45 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 5:22 pm
Posts: 423
It's even possible to play an AVI and to change it's playback-speed.

_________________
%1>>1+1*1/1-1!1|1&1<<$1=1


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 11, 2003 7:40 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13595
Location: France
The Movie commands should be able to do that too.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 11, 2003 8:45 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 5:22 pm
Posts: 423
I cannot find a Movie-command for changing the playback-speed ?!

_________________
%1>>1+1*1/1-1!1|1&1<<$1=1


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 11, 2003 9:30 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 6:41 pm
Posts: 1356
And the movie-lib don't return playingtime in ms...


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Nov 12, 2003 11:42 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13595
Location: France
I overlooked that :)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Nov 12, 2003 6:53 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 6:41 pm
Posts: 1356
Fred wrote:
I overlooked that :)


Also a PAN-Function for Sound would be nice...


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Nov 12, 2003 7:32 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 5:22 pm
Posts: 423
@GPI:
Do you overlooked THAT ? :D

SoundPan(#Sound, Balance)

_________________
%1>>1+1*1/1-1!1|1&1<<$1=1


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Nov 12, 2003 9:42 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 6:41 pm
Posts: 1356
Froggerprogger wrote:
@GPI:
Do you overlooked THAT ? :D

SoundPan(#Sound, Balance)


for Move-Sound... And ups. alread exist... (don't play much with move and PB...)

btw: Maybe a optional Type-Parameter for the Info/seek/length/Status, like #PB_Move_Frame,#PB_Move_ms)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Nov 14, 2003 4:30 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 4:57 pm
Posts: 573
Brilliant - really, really useful - I wish I were able to understand it ;-)

- is there an way to alter pitch and tempo (or speed) independantly, though?

- I had a plugin for WinAmp that lets you do that, so I guess it must be possible at least...

Thanks very much - NAW

_________________
Ta - N


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: kvitaliy and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye