help needed with scrollbar&windows media player

carly

New member
Joined
Apr 3, 2008
Messages
3
Programming Experience
Beginner
I thought this would work if i just added the code to play a certain track on the media player but this doesnt work



what i want, is when the user selects a certain station from the scroll bar, another mp3 is played, depending on which station is selected...



this is the code i have so far...

and the

MediaPlayer1.URL = "c:\Kylie.mp3"

does not work although i thought it would.



Anybody got any idea how i need to do this? I thought it would be simple enough to just call another song to the media player.



the media player btw is on the first form, not the second form and should start playing the newly selected track when the user presses the select button, otherwise, if the user selects the cancel button, the song which was playing before the user selected the scan button on the first form, should carry on playing.



:-(



First form code:


VB.NET:
Code SnippetPrivate Sub btnPower_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPower.Click

If Mode = ModeEnum.OffMode Then

Mode = ModeEnum.OnMode

MediaPlayer1.URL = "c:\ChrisBrown.mp3"

Else

Mode = ModeEnum.OffMode

MediaPlayer1.Ctlcontrols.stop()


 

End If

SetMode(Me, Mode)

End Sub

Private Mode As ModeEnum = ModeEnum.OffMode

Enum ModeEnum

OnMode

OffMode

End Enum

Sub SetMode(ByVal ctl As Control, ByVal mode As ModeEnum)

Dim blnEnabled As Boolean = (mode = ModeEnum.OnMode)

For Each subCtl As Control In ctl.Controls

If Not subCtl.Name = "btnPower" Then

subCtl.Enabled = blnEnabled

End If

If subCtl.HasChildren Then SetMode(subCtl, mode)

Next

 

 

End Sub

Private Sub TckbarVolume_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TckbarVolume.Scroll

MediaPlayer1.settings.volume = TckbarVolume.Value * 10

End Sub

 

 

 

 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

 

SetMode(Me, ModeEnum.OffMode)

Dim fileName As String = "C:\lastStation.txt"

Dim textLine As String = String.Empty

Try

If System.IO.File.Exists("C:\lastStation.txt") Then

Dim reader As New System.IO.StreamReader(fileName)

Do While reader.Peek() <> -1

textLine += reader.ReadLine()

textLine += Environment.NewLine()

Loop

Else

textLine = "File not found!"

End If

Catch Ex As Exception

textLine = Ex.Message

End Try

lblStationInfo.Text = textLine

End Sub

Private Sub btnScan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScan.Click

MediaPlayer1.Ctlcontrols.pause()

Dim oForm As New Form2

oForm.ShowDialog()

MediaPlayer1.Ctlcontrols.play()

End Sub

 

Private Sub btnMute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMute.Click

If MediaPlayer1.settings.mute Then

MediaPlayer1.settings.mute = False

Else

MediaPlayer1.settings.mute = True

End If

End Sub

End Class







Second form code:



VB.NET:
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click

Me.Close()

End Sub

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim fileName As String = "C:\yourLocation.txt"

Dim textLine As String = String.Empty

Try

If System.IO.File.Exists("C:\yourLocation.txt") Then

Dim reader As New System.IO.StreamReader(fileName)

Do While reader.Peek() <> -1

textLine += reader.ReadLine()

textLine += Environment.NewLine()

Loop

Else

textLine = "File not found!"

End If

Catch Ex As Exception

textLine = Ex.Message

End Try

lblStationInfo.Text = textLine

End Sub

 

Private Sub scrollbarStations_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles scrollbarStations.ValueChanged

 

 

Select Case scrollbarStations.Value

Case 1

lblStationInfo.Text = "First Radio 2345 MW"

MediaPlayer1.URL = "c:\Kylie.mp3"

Case 2

lblStationInfo.Text = "Second Radio 6654 MW"

Case 3

lblStationInfo.Text = "Third Radio 7563 MW"

 

End Select

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

If scrollbarStations.Value < scrollbarStations.Maximum Then

scrollbarStations.Value = scrollbarStations.Value + 1

End If

End Sub

 

 

End Class
 
Back
Top