LoadNewMusic
Index = LoadNewMusic(Filename$)
 
Parameters:

    Filename$ = The file name of the music you wish to load
Returns:

    Index = The Index where this music data is stored
 

LoadNewMusic will load/que a Music file ready to be played. You must provide LoadNewMusic with the filename and path of the music you wish to load. LoadNewMusic return the Index that this music was stored in. Once the Music data has been loaded, you can play it using the PlayMusic command.




FACTS:


* LoadNewMusic Expects music files to be in the Wav\Ogg\Midi\Mod formats.

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



Mini Tutorial:


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

  
  
; Load the music up front
  MusicIndex=LoadNewMusic("..\..\..\Music\Ambient.xm")
  
  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(1)
        DeleteMusic MusicIndex
        MusicIndex=LoadNewMusic("..\..\..\Music\Ambient.xm")
     EndIf
     
   ; 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 | LoadMusic | LoadSound | LoopMusic | MusicVolume | PlayMusic | StopMusic :
 


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