Hello there!
Have you ever wanted to write your OWN media player and add the features you love into it?!
Well, this is definitely going to help you achieve what you want!.
So in this tutorial we'll be using DirectX..AudioVideoPlayback lib (Library) to play videos and music in our form, of course you can do this with Windows Media Player controls or even everyone's favorite VLC Player, but there's no fun in using other programs controls! Let's make our own
Prerequisites
Make sure you have all your prerequisites.checked=TRUE! and move to Step 1
Have you ever wanted to write your OWN media player and add the features you love into it?!
Well, this is definitely going to help you achieve what you want!.
So in this tutorial we'll be using DirectX..AudioVideoPlayback lib (Library) to play videos and music in our form, of course you can do this with Windows Media Player controls or even everyone's favorite VLC Player, but there's no fun in using other programs controls! Let's make our own
Prerequisites
- The DirectX latest SDK (Software Development Kit) which can be found here
- The Visual Studio IDE (Integrated Development Environment). You can get a free version from here ,or you can use any other IDE.
- A Computer
- A Keyboard
- AAAND!! A Screen :D
Make sure you have all your prerequisites.checked=TRUE! and move to Step 1
LETS START!!!
Step 1:
Create a new project and name it whatever you want!, I will call mine "MyNOTSimplePlayer"
Yes yes, I still use Windows XP :)
The form will be very simple, we'll only add a Panel control, three buttons and an OpenFileDialog tool.
Don't worry we'll get to more advanced features in the coming tutorials :)
Step 2:
Add the Following:
- A Panel control (Panel1)
- Three Buttons (Button1,Button2,Button3) and name them (Play , Pause , Stop)
- An Open File Dialog control (OpenFileDialog1)
Step 3:
and then browse to ("Drive":\Program Files\Microsoft DirectX SDK (March 2008)\Developer Runtime\x86\DirectX for Managed Code) and choose Microsoft.DirectX.AudioVideoPlayback.dll
Step 4:
Now we get to the best part CODING! ;D
go to the code window and add to the very first line Imports Microsoft.DirectX.AudioVideoPlayback
go to the code window and add to the very first line Imports Microsoft.DirectX.AudioVideoPlayback
so we can use the library.
Now double click on the "Play" button and add this code>>>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
myVideo = New Video(OpenFileDialog1.FileName)
myVideo.Owner = Panel1
myVideo.Play()
End If
End Sub
myVideo = New Video(OpenFileDialog1.FileName)
myVideo.Owner = Panel1
myVideo.Play()
End If
End Sub
Explaining the code>>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
'Accepts the code only if the dialog accepts a file
myVideo = New Video(OpenFileDialog1.FileName)'
'Returns the path of the File Dialog and gives it to "myVideo"
myVideo.Owner = Panel1
'Here's the awesome part,, makes the owner (Were the video will run) Panel1
myVideo.Play()
myVideo.Play()
End If
End Sub
This is how the code will Look like!
Now the pause and the stop are VERY simple!!
The code for PAUSE is [myVideo.Pause()]
The code for PAUSE is [myVideo.Pause()]
The code for STOP is [myVideo.Stop()]
Now try running the program!! :D
Hope you enjoyed this tutorial! and you'll see more in the next tutorial :D
Thanks for reading!
Thanks for reading!
No comments:
Post a Comment