PlayMusic
PlayMusic Index
 
Parameters:

    Index = The Index of Music you wish to Play
Returns: NONE
 

PlayMusic will start a previously loaded music playing.




FACTS:


* Unlike the Sounds command, PlayMusic spools the music source off the disc while playing.

* You can find this Example in the PlayBasic\Projects\Music folder

* Beware: Some Music Mod formats (I.e. MOD, XM etc) can be set up (by the music author) to never end, as such, those tracks will loop regardless !




Mini Tutorial:


This example will load a music file then let the user control the musics playback with various keyboard controls.

  
; Ask PB for a free Music Index
  MusicIndex=GetFreeMusic()
  
  
  Do
     
     Cls RGB(0,0,0)
     
   ; Display Instructions
     Print "Music Example"
     Print ""
     Print " F1 = Load Music"
     Print " F2 = Play Music"
     Print " F3 = Pause Music"
     Print " F4 = Resume Music"
     Print " F5 = Stop Music"
     
     Print " Up/Down Arrows = Volume Control"
     Print " Left/Right Arrows = Pan Control"
     
     Print ""
     
     
   ; Load the load track (init streaming of this track)
     If FunctionKeys(1Then LoadMusic "..\..\..\Music\Ambient.xm",MusicIndex
     
   ; Get the Status of the music
     If GetMusicStatus(Musicindex)=true
        
      ; If the F2 key is pressed play the music
        If FunctionKeys(2Then  PlayMusic MusicIndex
      ; If the F3 key is pressed Pause the music
        If FunctionKeys(3Then  PauseMusic MusicIndex
      ; If the F4 key is pressed Resume the music
        If FunctionKeys(4Then  ResumeMusic MusicIndex
      ; If the F5 key is pressed Stop the music
        If FunctionKeys(5Then  StopMusic MusicIndex
        
        Volume=GetMusicVolume(MusicIndex)
      ; If the Up arrow is pressed increase the volume
        If UpKey() Then        MusicVolume MusicIndex,Volume+1
      ; If the Down arrow is pressed decrease the volume
        If DownKey() Then        MusicVolume MusicIndex,Volume-1
        
      ; Get the Pan of the music
        Pan=GetMusicPan(MusicIndex)
      ; if the Left arrow is press pan the music left
        If LeftKey() Then        MusicPan MusicIndex,Pan-1
        
      ; if the Right arrow is press pan the music Right
        If RightKey() Then   MusicPan MusicIndex,Pan+1
        
     Else
        Volume=0
        pan=0
     EndIf
     
   ;Display the Music Status
     Print ""
     Print " Music Current Status:"+Str$(GetMusicStatus(1))
     Print " Music Current Volume:"+Str$(Volume)
     Print " Music Current    Pan:"+Str$(Pan)
     
     Print ""
     
   ; Show the Music playing Status
     Select GetMusicPlaying(MusicIndex)
         Case -1
             mode$="Music is Not LOADED"
             
         Case 0
             mode$= "Music Is Loaded but Not Playing"
             
         Case 1
             Mode$= "Music Is Playing"
             
         Case 2
             Mode$="Music Paused"
             
         Case 3
             Mode$="Music Playing + Paused"
     EndSelect
     
     
     Print "Current Music Status:"+mode$
     
   ; Delete all music tracks if the space key is pressed
     If SpaceKey()
        DeleteAllMusics
     EndIf
     
   ; refresh the screen
     Sync
   ; loop back to the DO statement
  Loop
  
  
  
  
  




 
Related Info: DeleteMusic | GetFreeMusic | GetMusicPlaying | LoadMusic | LoadNewMusic | LoopMusic | MusicVolume | PauseMusic | ResumeMusic | StopMusic :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com