Guidance
指路人
g.yi.org
software / rapidq / Examples / Audio & Video / sonido.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'===========================================================================
' Subject: SONIDO 1.0 (MP3 PLAYER)           Date: 08-29-00 (01:50)
' Author:  Gerome Guillemin                  Code: RAPIDQ
' Origin:  gedd123@free.fr                 Packet: RAPIDQ.ABC
'===========================================================================
' Sonido 1.0 : hidden MCI command to play MP3 Files with PC equipped with Windows 9.x, NT or Win2k
' equipped with MS-Media Player 2 or higher
' Author : Gerome GUILLEMIN (FRANCE)
' Mailto : gedd123@free.fr
' Web page : http://gedd123.free.fr (My own MP3 rippers/encoders, Rapid-Q source code...)
' Feel free to use this snippet to play your favorite MP3 files
' Started : 08-08-2000  - Modified 08-29-2000 at 10.30 PM (huh... what a good programming time :)
' This code is dedicated to William's Great Rapid-Q compiler and for all basic code lovers !
' This code is also dedicated to ABC packets if William decides to packet it :)
' BUG fixed in this release : shorten paths & mp3 filename oops... :(
' Improvements : Added a way to 'registrize' MP3 files with Sonido :)
' THIS CODE HAS BEEN FULLY DOCUMENTED - TELL ME IF SOMETHING IS MISSING - THANKS A LOT -

' Security / Optimizations
     $INCLUDE "Rapidq.inc"
     $TYPECHECK ON   ' Useful for me :)
     $OPTIMIZE ON    ' Yeah...
     $OPTION Level 3 ' For Fun

' Global Definitions / Prototypes
     $DEFINE FALSE  0
     $DEFINE TRUE   1
     DECLARE SUB Button1Click (Sender AS QBUTTON)
     DECLARE SUB Button2Click (Sender AS QBUTTON)
     DECLARE SUB Button3Click (Sender AS QBUTTON)

' Main API Declaration
     DECLARE FUNCTION mciSendString LIB "winmm.dll" ALIAS "mciSendStringA" _
      (BYVAL lpstrCommand AS STRING, BYVAL lpstrReturnString AS STRING, BYVAL uReturnLength AS LONG, _
      BYVAL hwndCallback AS LONG) AS LONG

' Globals
     DIM ret AS LONG            ' Returned value for 'mciSendString'
     DIM mp3file AS STRING      ' Name of the MP3 to play
     DIM nCounter AS INTEGER    ' Counter to manage the action Playing/Pausing/Continuing...
     DIM szCmd AS STRING        ' MCI Command -> Open
     DIM szPlay AS STRING       ' MCI Command -> Play Sonido
     DIM szRegCmd AS STRING     ' String for MP3 File description for the Registry

' My constants
     mp3file = COMMAND$(1) 'old code was this (hard coded) -> "D:\REGS\Rapid-Q\Projets\GG_Works\Sonido\01-Zarathoustra.mp3" '-> change this to a valid MP3 filename from your PC
     szCmd = "Open " & CHR$(34) & mp3file & CHR$(34) & " Alias Sonido"
     szPlay = "Play sonido"

     CONST HKEY_CLASSES_ROOT = &H80000000     ' Registry constant (William has forgotten to document this one !)

     $ESCAPECHARS ON 'Put this on the Top of the code to avoid conflicts !

     DIM Registry AS QREGISTRY

     CREATE Form AS QFORM
      CAPTION = "Sonido : FREE MP3 Player"
      Width = 320
      Height = 115
      Center
      CREATE Button1 AS QBUTTON
       CAPTION = "Play !"
       Left = 9
       Top = 10
       OnClick = Button1Click
      END CREATE
      CREATE Button2 AS QBUTTON
       CAPTION = "Stop !"
       Left = 89
       Top = 10
       TabOrder = 1
       OnClick = Button2Click
      END CREATE
      CREATE Button3 AS QBUTTON
       CAPTION = "Associate MP3@Sonido !"
       Left = 170
       Top = 10
       Width = 135
       TabOrder = 1
       OnClick = Button3Click
      END CREATE

      CREATE Label1 AS QLABEL
       Align = 2
       Alignment = 2
       COLOR = &hFFFF
       CAPTION = "By Gérôme GUILLEMIN 08-08-2000\nMailto: gedd123@free.fr\nWeb: http://gedd123.free.fr" '-> fatidic date : 11 years ago i've succeded my driving code license :)
       Left = 29 '-> will be my age the 12th of August 2000 ;)
       Top = 40  '-> cool height for my screen :)
      END CREATE
     END CREATE

'Initialization code
     IF COMMAND$(1) <> "" THEN
      ret = mciSendString(szCmd, 0, 0, 0)          ' Open the MP3 file
      ret = mciSendString(szPlay, 0, 0, 0)         ' Plays the MP3 file !
      Button1.CAPTION = "Playing..." : nCounter = 1
     END IF

     Form.SHOWMODAL


'--------- Subroutines ---------

     SUB Button1Click (Sender AS QBUTTON)

'nCounter manages the action for the MP3 -> 0 == Plays or Continue // 1 == Pauses the MP3
      SELECT CASE nCounter

      CASE 0
       ret = mciSendString(szCmd, 0, 0, 0) 'Open the MP3 file
       IF ret <> 0 AND Button1.CAPTION = "Play !" THEN
        SHOWMESSAGE ("Invalid Handle -> MP3 File is not present or may be an invalid MP3 file !")
        Button1.Enabled = FALSE
       ELSE
         '? ret 'left for debugging
       END IF
       Button1.CAPTION = "Playing..." : nCounter = 1
       ret = mciSendString(szPlay, 0, 0, 0)         ' Plays the MP3 file !

      CASE 1
       ret = mciSendString("Stop sonido", 0, 0, 0)  ' Pause (if we want to wait a while for a cup of tea :)
       Button1.CAPTION = "Paused !" : nCounter = 0
      END SELECT

     END SUB


     SUB Button2Click (Sender AS QBUTTON)
      ret = mciSendString("Stop sonido", 0, 0, 0)  ' Pause (if we want to wait a while for a second cup of tea :)
      ret = mciSendString("Close sonido", 0, 0, 0) ' Stop Playing MP3 file (the file is rewinded at this moment)
     END SUB


     SUB Button3Click (Sender AS QBUTTON)      ' Associate MP3 files with Sonido !
      szRegCmd = COMMAND$(0) + " \34%1\34"      ' Full Path for Sonido + command

      Registry.RootKey = HKEY_CLASSES_ROOT
      Registry.OpenKey("\\.mp3", 1)
      Registry.WriteString("", "Sonido File")

      Registry.OpenKey("\\Sonido File", 1)
      Registry.WriteString("", "MP3 File")
      Registry.OpenKey("shell\\open\\command", 1)
      Registry.WriteString("", szRegCmd)

      SHOWMESSAGE ("MP3 files successfully associated with Sonido :)\nJust click onto an MP3 file...\nEnjoy :-p")
      Application.Terminate ' The 1st job is done... it's time to play mp3 now !
     END SUB
掌柜推荐
 
 
¥289.00 ·
 
 
¥1,080.00 ·
 
 
¥1,380.00 ·
 
 
¥638.00 ·
 
 
¥1,290.00 ·
 
 
¥1,420.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-19 07:40:30