dlegendkiller
30th Jan 2008 Wed, 20:45
nakakita ako na tutorial sa net pero indi working ehh...
e2 instruction nila:
Add a Windows Media Player control to your project and then add the following to your Form_Load():
MediaPlayer1.FileName = "C:\exact path to sound file"
MediaPlayer1.Play
help po pls
hmx_ryan
1st Feb 2008 Fri, 12:48
Pwede mong gamitin ang DirectShow ng DirectX... Pwedeng mong i-play ang MP3's and other media types, pati mga videos.... The difference is that, DirectShow gives you more control over your media. To access DirectShow, all you do is go up in the menu to Project > References... and add Active Movie Control Type Library into your references.
Then add a module into your project and put this code in:
'This module play MP3 File using the DirectShow of DirectX
'by: hmx_ryan
'symbianize.com
Private Const MAX_VOLUME As Long = 100
Private Const MAX_BALANCE As Long = 100
Private Const MAX_SPEED As Long = 226
Public DirectShow_Event As IMediaEvent
Public DirectShow_Control As IMediaControl
Public DirectShow_Position As IMediaPosition
Public DirectShow_Audio As IBasicAudio
Public Function DirectShow_Load_Media(File_Name As String) As Boolean
On Error GoTo Error_Handler
If Right(File_Name, 4) = ".mp3" Then
Set DirectShow_Control = New FilgraphManager
DirectShow_Control.RenderFile (File_Name)
Set DirectShow_Audio = DirectShow_Control
DirectShow_Audio.Volume = 0
DirectShow_Audio.Balance = 0
Set DirectShow_Event = DirectShow_Control
Set DirectShow_Position = DirectShow_Control
DirectShow_Position.Rate = 1
DirectShow_Position.currentPosition = 0
Else
GoTo Error_Handler
End If
DirectShow_Load_Media = True
Exit Function
Error_Handler:
DirectShow_Load_Media = False
End Function
Public Function DirectShow_Play() As Boolean
On Error GoTo Error_Handler
DirectShow_Control.Run
DirectShow_Play = True
Exit Function
Error_Handler:
DirectShow_Play = False
End Function
Public Function DirectShow_Stop() As Boolean
On Error GoTo Error_Handler
DirectShow_Control.Stop
DirectShow_Position.currentPosition = 0
DirectShow_Stop = True
Exit Function
Error_Handler:
DirectShow_Stop = False
End Function
Public Function DirectShow_Pause() As Boolean
On Error GoTo Error_Handler
DirectShow_Control.Stop
DirectShow_Pause = True
Exit Function
Error_Handler:
DirectShow_Pause = False
End Function
Public Function DirectShow_Volume(ByVal Volume As Long) As Boolean
On Error GoTo Error_Handler
If Volume >= MAX_VOLUME Then Volume = MAX_VOLUME
If Volume <= 0 Then Volume = 0
DirectShow_Audio.Volume = (Volume * MAX_VOLUME) - 10000
DirectShow_Volume = True
Exit Function
Error_Handler:
DirectShow_Volume = False
End Function
Public Function DirectShow_Balance(ByVal Balance As Long) As Boolean
On Error GoTo Error_Handler
If Balance >= MAX_BALANCE Then Balance = MAX_BALANCE
If Balance <= -MAX_BALANCE Then Balance = -MAX_BALANCE
DirectShow_Audio.Balance = Balance * MAX_BALANCE
DirectShow_Balance = True
Exit Function
Error_Handler:
DirectShow_Balance = False
End Function
Public Function DirectShow_Speed(ByVal Speed As Single) As Boolean
On Error GoTo Error_Handler
If Speed >= MAX_SPEED Then Speed = MAX_SPEED
If Speed <= 0 Then Speed = 0
DirectShow_Position.Rate = Speed / 100
DirectShow_Speed = True
Exit Function
Error_Handler:
DirectShow_Speed = False
End Function
Public Function DirectShow_Set_Position(ByVal Hours As Long, ByVal Minutes As Long, ByVal Seconds As Long, Milliseconds As Single) As Boolean
On Error GoTo Error_Handler
Dim Max_Position As Single
Dim Position As Double
Dim Decimal_Milliseconds As Single
'Keep minutes within range
Minutes = Minutes Mod 60
'Keep seconds within range
Seconds = Seconds Mod 60
'Keep milliseconds within range and keep decimal
Decimal_Milliseconds = Milliseconds - Int(Milliseconds)
Milliseconds = Milliseconds Mod 1000
Milliseconds = Milliseconds + Decimal_Milliseconds
'Convert Minutes & Seconds to Position time
Position = (Hours * 3600) + (Minutes * 60) + Seconds + (Milliseconds * 0.001)
Max_Position = DirectShow_Position.StopTime
If Position >= Max_Position Then
Position = 0
GoTo Error_Handler
End If
If Position <= 0 Then
Position = 0
GoTo Error_Handler
End If
DirectShow_Position.currentPosition = Position
DirectShow_Set_Position = True
Exit Function
Error_Handler:
DirectShow_Set_Position = False
End Function
Public Function DirectShow_End() As Boolean
On Error GoTo Error_Handler
If DirectShow_Loop = False Then
If DirectShow_Position.currentPosition >= DirectShow_Position.StopTime Then DirectShow_Stop
End If
DirectShow_End = True
Exit Function
Error_Handler:
DirectShow_End = False
End Function
Public Function DirectShow_Loop() As Boolean
On Error GoTo Error_Handler
If DirectShow_Position.currentPosition >= DirectShow_Position.StopTime Then
DirectShow_Position.currentPosition = 0
End If
DirectShow_Loop = True
Exit Function
Error_Handler:
DirectShow_Loop = False
End Function
Public Sub DirectShow_Shutdown()
Set DirectShow_Audio = Nothing
Set DirectShow_Event = Nothing
Set DirectShow_Control = Nothing
Set DirectShow_Position = Nothing
End Sub
Then add this code to your form
Option Explicit
Private Sub Form_Activate()
'Change the file path of your mp3 in here.
DirectShow_Load_Media "C:\Your MP3.mp3"
'You don't need to do this part, but it's nice to be
DirectShow_Volume 100
DirectShow_Balance 0
DirectShow_Speed 100
DirectShow_Set_Position 0, 0, 0, 0
DirectShow_Play
End Sub
Private Sub Form_Unload(Cancel As Integer)
DirectShow_Shutdown
End Sub
Note: You can even control the Play, Stop, Pause, Loop, Speed, Volume, Balance, Position, etc... Just invoke the Functions...
Leerz
3rd Feb 2008 Sun, 06:42
nakakita ako na tutorial sa net pero indi working ehh...
e2 instruction nila:
Add a Windows Media Player control to your project and then add the following to your Form_Load():
MediaPlayer1.FileName = "C:\exact path to sound file"
MediaPlayer1.Play
help po pls
make sure you've added the media player control on your project/form
check if the names you're using matches the controls you've added.