Join 300,479 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,752 people online right now. Registration is fast and FREE... Join Now!
Ingredients: 2 track bar(volume and trackposition) 1 progress bar(trackposition1) 5 buttons(but_next, play, back ,pause and stop) 4 labels listview(tracklist and 1 colum named trackcol) 1 menustrip and create 8 downstrip(play, pause, fast forward, next, stop, volume up, volume down, exit
CODE
Public Class Media_Player #Region "Color Settings" Dim CurrentTrackColor As System.Drawing.Color = Color.Red Dim PausedTrackColor As System.Drawing.Color = Color.LightYellow #End Region ' Dim opendrive As WMPLib.WindowsMediaPlayer ' Dim i As Integer ' Dim total As Integer Dim WithEvents vplayer As New AxWIAVIEWLib.AxVideoPreview Dim WithEvents Player As New WMPLib.WindowsMediaPlayer Dim files As Collections.ObjectModel.ReadOnlyCollection(Of String) Dim titles As New List(Of String) Dim CurrentPlaying As Integer = 0 Dim PreviouslyPlaying As Integer = 0 Private Sub but_Play_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_Play.Click GUIMode("Play") updatePlayer() Player.controls.play()
End Sub
Private Sub but_Pause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_Pause.Click
If Player.playState = WMPLib.WMPPlayState.wmppsPaused Then GUIMode("Play") Else GUIMode("Paused") End If End Sub
Private Sub but_Stop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_Stop.Click Player.controls.stop() GUIMode("Stopped") End Sub
Private Sub Volume_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Volume.Scroll Player.settings.volume = Volume.Value Label3.Text = Volume.Visible End Sub
Private Sub TrackPosition_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackPosition.Scroll Player.controls.pause() Player.controls.currentPosition = ProgressBar1.Value 'Label9.Text = Player.controls.currentPosition Player.controls.currentPosition = TrackPosition.Value Player.controls.play() updatePlayer() ' Allow the app to do some processing Application.DoEvents() End Sub
Private Sub Media_Player_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed Player = Nothing End Sub
Private Sub Media_Player_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing Player.close() End Sub
Private Sub Media_Player_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Label7.Text = "Created By Mangciphu Zola" 'Me.BackgroundImage.Clone() Randomize() ' Me.Label3.Text = ShowInTaskbar Label5.Text = Player.versionInfo Label2.Text = TrackList.Items.Count 'ShowInTaskbar = Me.Label3.Text Player.windowlessVideo = True but_Pause.Enabled = True but_Stop.Enabled = True 'hide the progress bar which display the track position ProgressBar1.Visible = False Label10.Text = Player.controls.currentPosition 'set the place where you want this player to get them automatic files = FileIO.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.Desktop, FileIO.SearchOption.SearchAllSubDirectories, "*.mp3") files = FileIO.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.MyPictures, FileIO.SearchOption.SearchAllSubDirectories, "*.mp3") files = FileIO.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData, FileIO.SearchOption.SearchAllSubDirectories, "*.mp3") files = FileIO.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.MyMusic, FileIO.SearchOption.SearchAllSubDirectories, "*.mp3", "*.wav", "*.mp4", "*.avi", "*.MPEG") For Each a As String In files Me.TrackList.Items.Add(FileIO.FileSystem.GetName(a)) Next Volume.Value = Player.settings.volume
Me.Text = ScrollStateVScrollVisible With (Me.Timer1.Interval = 500) Timer1.Start() Enabled = True End With End Sub Private Sub GUIMode(ByRef Guimode As String) Select Case Guimode Case ("Play") ' Put GUI in playing mode guise Player.controls.play() but_Pause.BackColor = System.Drawing.SystemColors.Control but_Pause.Enabled = True but_Stop.Enabled = True Label4.Text = Player.status but_Play.Enabled = True Case ("Paused") ' put gui in paused mode guise but_Pause.Enabled = True but_Stop.Enabled = False but_Play.Enabled = False but_Pause.BackColor = PausedTrackColor Player.controls.pause() Case ("Stopped") but_Pause.Enabled = False but_Stop.Enabled = False
End Select
End Sub
Private Sub Player_MediaError(ByVal pMediaObject As Object) Handles Player.MediaError MessageBox.Show("Unrecoverable Problem. Shutting Down", "MyMusic Player") Me.Close() End Sub
Private Sub Player_PlayStateChange(ByVal NewState As Integer) Handles Player.PlayStateChange Static Dim PlayAllowed As Boolean = True Select Case CType(NewState, WMPLib.WMPPlayState) Case (WMPLib.WMPPlayState.wmppsReady) If PlayAllowed Then Player.controls.play() End If Case (WMPLib.WMPPlayState.wmppsMediaEnded) ' Reach end of track move onto next, looping around PreviouslyPlaying = CurrentPlaying CurrentPlaying = (CurrentPlaying + 1) Mod files.Count ' Start protection (without it next wouldn't play PlayAllowed = False ' Play track Player.URL = files(CurrentPlaying) Player.controls.play() ' End Protection PlayAllowed = True updatePlayer() End Select Label4.Text = Player.status Label10.Text = Player.controls.currentPosition.ToString End Sub
Private Sub updatePlayer() ' Display track name 'txt_TrackName.Text = Player.currentMedia.name ' Label8.Text = Player.currentMedia.name ' ShowInTaskbar = Label3.Text 'Label3.Text = ShowInTaskbar ' txt_TrackArtist.Text = Player.status ' Update TrackPostion With (ProgressBar1) ProgressBar1.Minimum = 0 ProgressBar1.Maximum = Val(Player.currentMedia.duration) ProgressBar1.Value = Val(Player.controls.currentPosition()) End With With (TrackPosition) TrackPosition.Minimum = 0 TrackPosition.Maximum = CInt(Player.currentMedia.duration) TrackPosition.Value = CInt(Player.controls.currentPosition()) End With ' Display Current Time Position and Duration 'txt_Progress.Text = Player.controls.currentPositionString & vbTab & Player.currentMedia.durationString 'Label4.Text = txt_Progress.Text = Player.controls.currentPositionString & vbTab & Player.currentMedia.durationString ' Set Volume slide to match current volume Volume.Value = Player.settings.volume ' Is the CurrentPlaying Track No. is different to the Previous Track number. If CurrentPlaying <> PreviouslyPlaying Then ' Yes, ' Set the forecolor of the corrisponding track, assiociated with the previous playing track, with the control color TrackList.Items(PreviouslyPlaying).ForeColor = System.Drawing.SystemColors.ControlText End If ' Set the forecolor of the corrisponding track, assiociated with the currently playing track, with the current track color TrackList.Items(CurrentPlaying).ForeColor = CurrentTrackColor Label4.Text = Player.status End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' MessageBox.Show("Are You Sure About that? and the playing track is ...", Me.Text, MessageBoxButtons.YesNo) Label4.Text = Player.status ' Me.Text = ScrollStateAutoScrolling 'ProgressBar1.Style = Me.Text ' Label4.Text = ShowInTaskbar.ToString ' Player.controls.currentItem.name = ShowInTaskbar 'it displays the playing track on the taskbar Me.Text = Player.controls.currentItem.name & " " & Label10.Text SetScrollState(8, True) 'this shows the total time of a track Label9.Text = Player.controls.currentItem.durationString 'the current time of a track Label10.Text = Player.controls.currentPositionString ' Label11.Text = Label3.Text = Volume.Value.ToString & "%" REM Label11.Text = Player.controls.currentItem.attributeCount updatePlayer() Label1.Text = DateAndTime.Now End Sub
Private Sub TrackList_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) GUIMode("Play") Randomize() ' A track in the tracklisting has been double clicked on PreviouslyPlaying = CurrentPlaying ' Set CurrentPlaying to position of selected track. CurrentPlaying = TrackList.SelectedIndices(0) ' Play the track Player.URL = files(CurrentPlaying) updatePlayer() Player.controls.play() End Sub
Private Sub MuteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MuteToolStripMenuItem.Click Player.settings.mute = True End Sub
Private Sub PlayToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayToolStripMenuItem.Click GUIMode("Play") updatePlayer() Player.controls.play() Label10.Text = Player.controls.currentPosition.ToString End Sub
Private Sub but_Next_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_Next.Click Randomize() ' A track in the tracklisting has been double clicked on PreviouslyPlaying = CurrentPlaying ' Set CurrentPlaying to position of selected track.
' Play the track Player.URL = files(CurrentPlaying) updatePlayer() Player.controls.play()
Private Sub StopToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopToolStripMenuItem.Click Player.controls.stop() GUIMode("Stopped") End Sub
Private Sub PauseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PauseToolStripMenuItem.Click If Player.playState = WMPLib.WMPPlayState.wmppsPaused Then GUIMode("Play") Else GUIMode("Paused") End If End Sub
Private Sub FastForwardToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FastForwardToolStripMenuItem.Click Player.controls.fastForward()
End Sub
Private Sub FastRewindToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FastRewindToolStripMenuItem.Click Player.controls.fastReverse() End Sub
Private Sub but_Back_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_Back.Click Randomize() ' A track in the tracklisting has been double clicked on PreviouslyPlaying = CurrentPlaying ' Set CurrentPlaying to position of selected track.
' Play the track Player.URL = files(CurrentPlaying) updatePlayer() Player.controls.play()
Private Sub RedToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedToolStripMenuItem.Click
Me.BackColor = Color.Red End Sub
Private Sub ShowAdvanceSeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowAdvanceSeToolStripMenuItem.Click TrackPosition.Visible = False ProgressBar1.Visible = True End Sub
Private Sub NormalSeekToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NormalSeekToolStripMenuItem.Click TrackPosition.Visible = True ProgressBar1.Visible = False End Sub Private Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgressBar1.Click Player.controls.play() updatePlayer() ' Allow the app to do some processing Application.DoEvents() End Sub
Private Sub TrackList_DoubleClick1(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackList.DoubleClick GUIMode("Play") Randomize() ' A track in the tracklisting has been double clicked on PreviouslyPlaying = CurrentPlaying ' Set CurrentPlaying to position of selected track. CurrentPlaying = TrackList.SelectedIndices(0) ' Play the track Player.URL = files(CurrentPlaying) updatePlayer() Player.controls.play() End Sub
Private Sub NextToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextToolStripMenuItem.Click Randomize() ' A track in the tracklisting has been double clicked on PreviouslyPlaying = CurrentPlaying ' Set CurrentPlaying to position of selected track.
' Play the track Player.URL = files(CurrentPlaying) updatePlayer() Player.controls.play()
Player.controls.next() Player.controls.play() End Sub
Private Sub BackToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackToolStripMenuItem.Click Randomize() ' A track in the tracklisting has been double clicked on PreviouslyPlaying = CurrentPlaying ' Set CurrentPlaying to position of selected track.
' Play the track Player.URL = files(CurrentPlaying) updatePlayer() Player.controls.play()
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click Me.Close() End Sub
Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click Player.settings.volume = Volume.Value + 1 End Sub
Private Sub ToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem3.Click Player.settings.volume = Volume.Value + 2 End Sub
Private Sub ToolStripMenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem4.Click Player.settings.volume = Volume.Value + 5 End Sub
Private Sub ToolStripMenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem5.Click Player.settings.volume = Volume.Value + 10 End Sub
Private Sub ToolStripMenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem6.Click Player.settings.volume = Volume.Value + 20 End Sub
Private Sub ToolStripMenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem7.Click Player.settings.volume = Volume.Value + 50 End Sub
Private Sub ToolStripMenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem8.Click Player.settings.volume = Volume.Value - 1 End Sub
Private Sub ToolStripMenuItem9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem9.Click Player.settings.volume = Volume.Value - 2 End Sub
Private Sub ToolStripMenuItem10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem10.Click Player.settings.volume = Volume.Value - 5 End Sub
Private Sub ToolStripMenuItem11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem11.Click Player.settings.volume = Volume.Value - 10 End Sub
Private Sub ToolStripMenuItem12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem12.Click Player.settings.volume = Volume.Value - 20 End Sub
Private Sub ToolStripMenuItem13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem13.Click Player.settings.volume = Volume.Value - 50 End Sub
Private Sub ShuffleToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShuffleToolStripMenuItem.Click Randomize() ' A track in the tracklisting has been double clicked on PreviouslyPlaying = CurrentPlaying ' Set CurrentPlaying to position of selected track.
' Play the track Player.URL = files(CurrentPlaying) updatePlayer() Player.controls.play()
GUIMode("Random") updatePlayer() For i = 0 To CurrentPlaying CurrentPlaying = Rnd(CurrentPlaying + 1) updatePlayer() Next Player.controls.previous() Player.controls.play() End Sub
Private Sub GreenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GreenToolStripMenuItem.Click Me.BackColor = Color.Green End Sub
Private Sub YellowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YellowToolStripMenuItem.Click Me.BackColor = Color.Yellow End Sub
Private Sub IndigoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IndigoToolStripMenuItem.Click Me.BackColor = Color.Indigo End Sub
Private Sub MaroonToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MaroonToolStripMenuItem.Click Me.BackColor = Color.Maroon End Sub
Private Sub PinkToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PinkToolStripMenuItem.Click Me.BackColor = Color.Pink End Sub
Private Sub LightBlueToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LightBlueToolStripMenuItem.Click Me.BackColor = Color.LightBlue End Sub
Private Sub DefaultToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DefaultToolStripMenuItem.Click Me.BackColor = Color.Empty End Sub End Class
right click on the toolbar,....... i don't remember which one u will choose but search for an object called windows media player or media player,i don't know if it belongs to com or activx controls
playing audio is much better oh here is the way that wasn't clear last time right click on toolbox>choose items>in the com tab,look for windows media player and mark the check box next to it and press ok u will find the windows media player as a tool in the toolbox it may not be in the toolox in the 'all windows forms area band then it will be with the general area when u add it,u will add it to the form normally after it is added to the form ,right click on it and choose properties to choose the file u want to play playing he file in other ways i may not know them, i have just discovered that part i told u now but it is working well i don't know if this is the best way to do so but if so then the code u made may not be important i hope this helps
playing audio is much better oh here is the way that wasn't clear last time right click on toolbox>choose items>in the com tab,look for windows media player and mark the check box next to it and press ok u will find the windows media player as a tool in the toolbox it may not be in the toolox in the 'all windows forms area band then it will be with the general area when u add it,u will add it to the form normally after it is added to the form ,right click on it and choose properties to choose the file u want to play playing he file in other ways i may not know them, i have just discovered that part i told u now but it is working well i don't know if this is the best way to do so but if so then the code u made may not be important i hope this helps
ok no problem in helping,if u mean how to make a scroll bar in a textbox,then i guess it happens if u made the texbox multiline,if it didn't work,try it in rich tectbox
scrolling word,in frontpage of office XP there was something like that calleld marqee if it is what he meant,the word goes right and left automatically