home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Stream_MP32029381162006.psc / Form1.frm < prev    next >
Text File  |  2006-11-06  |  7KB  |  236 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
  3. Begin VB.Form Form1 
  4.    BorderStyle     =   1  'Fest Einfach
  5.    Caption         =   "Stream MP3 and WMA from Resources"
  6.    ClientHeight    =   3000
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   5025
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   3000
  14.    ScaleWidth      =   5025
  15.    StartUpPosition =   3  'Windows-Standard
  16.    Begin VB.Timer tmrPos 
  17.       Enabled         =   0   'False
  18.       Interval        =   50
  19.       Left            =   4350
  20.       Top             =   0
  21.    End
  22.    Begin MSComctlLib.Slider sldPos 
  23.       Height          =   270
  24.       Left            =   150
  25.       TabIndex        =   3
  26.       Top             =   1125
  27.       Width           =   4665
  28.       _ExtentX        =   8229
  29.       _ExtentY        =   476
  30.       _Version        =   393216
  31.       TickStyle       =   3
  32.    End
  33.    Begin VB.CommandButton cmdStop 
  34.       Caption         =   "Stop"
  35.       Enabled         =   0   'False
  36.       Height          =   465
  37.       Left            =   3300
  38.       TabIndex        =   2
  39.       Top             =   300
  40.       Width           =   1515
  41.    End
  42.    Begin VB.CommandButton cmdPause 
  43.       Caption         =   "Pause"
  44.       Enabled         =   0   'False
  45.       Height          =   465
  46.       Left            =   1725
  47.       TabIndex        =   1
  48.       Top             =   300
  49.       Width           =   1515
  50.    End
  51.    Begin VB.CommandButton cmdPlay 
  52.       Caption         =   "Play"
  53.       Height          =   465
  54.       Left            =   150
  55.       TabIndex        =   0
  56.       Top             =   300
  57.       Width           =   1515
  58.    End
  59.    Begin MSComctlLib.Slider sldVol 
  60.       Height          =   270
  61.       Left            =   1125
  62.       TabIndex        =   6
  63.       Top             =   1875
  64.       Width           =   3690
  65.       _ExtentX        =   6509
  66.       _ExtentY        =   476
  67.       _Version        =   393216
  68.       Min             =   -10000
  69.       Max             =   0
  70.       TickStyle       =   3
  71.    End
  72.    Begin MSComctlLib.Slider sldBal 
  73.       Height          =   270
  74.       Left            =   1125
  75.       TabIndex        =   8
  76.       Top             =   2175
  77.       Width           =   3690
  78.       _ExtentX        =   6509
  79.       _ExtentY        =   476
  80.       _Version        =   393216
  81.       Min             =   -10000
  82.       Max             =   10000
  83.       TickStyle       =   3
  84.    End
  85.    Begin VB.Label Label1 
  86.       Caption         =   "MP3 gets played without being written to disk!"
  87.       Height          =   240
  88.       Left            =   300
  89.       TabIndex        =   9
  90.       Top             =   2625
  91.       Width           =   4515
  92.    End
  93.    Begin VB.Label lblBal 
  94.       Caption         =   "Balance:"
  95.       Height          =   240
  96.       Left            =   300
  97.       TabIndex        =   7
  98.       Top             =   2175
  99.       Width           =   690
  100.    End
  101.    Begin VB.Label lblVol 
  102.       Caption         =   "Volume:"
  103.       Height          =   240
  104.       Left            =   300
  105.       TabIndex        =   5
  106.       Top             =   1875
  107.       Width           =   690
  108.    End
  109.    Begin VB.Label lblPos 
  110.       AutoSize        =   -1  'True
  111.       Caption         =   "0:00/0:00"
  112.       Height          =   195
  113.       Left            =   3975
  114.       TabIndex        =   4
  115.       Top             =   1425
  116.       Width           =   705
  117.    End
  118. End
  119. Attribute VB_Name = "Form1"
  120. Attribute VB_GlobalNameSpace = False
  121. Attribute VB_Creatable = False
  122. Attribute VB_PredeclaredId = True
  123. Attribute VB_Exposed = False
  124. Option Explicit
  125.  
  126. Private WithEvents m_clsAudioMem    As AudioMemoryPlayer
  127. Attribute m_clsAudioMem.VB_VarHelpID = -1
  128.  
  129. Private m_blnDontMove               As Boolean
  130.  
  131. Private Sub cmdPause_Click()
  132.     If Not m_clsAudioMem.Pause() Then
  133.         MsgBox "Couldn't pause!"
  134.     End If
  135. End Sub
  136.  
  137. Private Sub cmdPlay_Click()
  138.     If Not m_clsAudioMem.Play() Then
  139.         MsgBox "Couldn't play!"
  140.     End If
  141. End Sub
  142.  
  143. Private Sub cmdStop_Click()
  144.     If Not m_clsAudioMem.StopPlayback() Then
  145.         MsgBox "Couldn't stop!"
  146.     End If
  147. End Sub
  148.  
  149. Private Sub Form_Load()
  150.     Dim btAudio()   As Byte
  151.     
  152.     Set m_clsAudioMem = New AudioMemoryPlayer
  153.  
  154.     ' load the MP3 file from the resource into btAudio
  155.     btAudio = LoadResData("MP3SOUND", "CUSTOM")
  156.     
  157.     ' OpenStream will copy btAudio into its own allocated memory,
  158.     ' btAudio can fall out of scope
  159.     If Not m_clsAudioMem.OpenStream(VarPtr(btAudio(0)), UBound(btAudio) + 1) Then
  160.         MsgBox "Couldn't open the audio stream!", vbExclamation
  161.         cmdPlay.Enabled = False
  162.     Else
  163.         sldPos.Max = m_clsAudioMem.Duration
  164.         sldPos.value = 0
  165.     End If
  166. End Sub
  167.  
  168. Private Sub Form_Unload(Cancel As Integer)
  169.     ' free allocated memory
  170.     m_clsAudioMem.CloseStream
  171. End Sub
  172.  
  173. Private Sub m_clsAudioMem_EndOfStream()
  174.     Debug.Print "End Of Stream!"
  175.     m_clsAudioMem_StatusChanged PlaybackStopped
  176. End Sub
  177.  
  178. Private Sub m_clsAudioMem_StatusChanged(ByVal stat As PlaybackStatus)
  179.     Select Case True
  180.         Case stat = PlaybackPausing
  181.             cmdPlay.Enabled = True
  182.             cmdPause.Enabled = False
  183.             cmdStop.Enabled = True
  184.             tmrPos.Enabled = False
  185.         Case stat = PlaybackPlaying
  186.             cmdPlay.Enabled = False
  187.             cmdPause.Enabled = True
  188.             cmdStop.Enabled = True
  189.             tmrPos.Enabled = True
  190.         Case stat = PlaybackStopped
  191.             cmdPlay.Enabled = True
  192.             cmdPause.Enabled = False
  193.             cmdStop.Enabled = False
  194.             tmrPos.Enabled = False
  195.     End Select
  196. End Sub
  197.  
  198. Private Sub sldBal_Scroll()
  199.     m_clsAudioMem.Balance = sldBal.value
  200. End Sub
  201.  
  202. Private Sub sldPos_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  203.     m_blnDontMove = True
  204. End Sub
  205.  
  206. Private Sub sldPos_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  207.     m_clsAudioMem.Position = sldPos.value
  208.     m_blnDontMove = False
  209. End Sub
  210.  
  211. Private Sub sldVol_Scroll()
  212.     m_clsAudioMem.Volume = sldVol.value
  213. End Sub
  214.  
  215. Private Sub tmrPos_Timer()
  216.     If Not m_clsAudioMem Is Nothing Then
  217.         With m_clsAudioMem
  218.             lblPos.Caption = FmtMs(.Position) & "/" & FmtMs(.Duration)
  219.             
  220.             If Not m_blnDontMove Then
  221.                 sldPos.value = .Position
  222.             End If
  223.         End With
  224.     End If
  225. End Sub
  226.  
  227. Private Function FmtMs(ByVal lngMS As Long) As String
  228.     Dim mins As Long, secs As Long
  229.     
  230.     secs = lngMS / 1000
  231.     mins = secs / 60
  232.     secs = secs Mod 60
  233.     
  234.     FmtMs = mins & ":" & Format(secs, "00")
  235. End Function
  236.