Sorry...it was actually an accident. I meant to put the code in the code tags. Easy mistake to make. SORRY.
Anyway...
I worked out that it was different versions so i have changed my code, and it now works using the different code to play, stop etc.
But i hit an error when i am trying to change the volume control on form 1. I have included the windows form design code as well as im not sure if it has anything to do with this as i had to remove/change parts of it to use the other version of windows media player.
If you have any idea why this error is coming up and how to fix it, please let me know asap...need this sorted asap!
Thanks
Carly
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in axinterop.mediaplayer.dll
Additional information: Exception occurred.
Form 1 Code:
CODE
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents btnPower As System.Windows.Forms.Button
Friend WithEvents btnScan As System.Windows.Forms.Button
Friend WithEvents lblStationInfo As System.Windows.Forms.Label
Friend WithEvents TckbarVolume As System.Windows.Forms.TrackBar
Friend WithEvents btnMute As System.Windows.Forms.Button
Public WithEvents radiobtnAM As System.Windows.Forms.RadioButton
Public WithEvents radiobtnFM As System.Windows.Forms.RadioButton
Friend WithEvents Station1 As System.Windows.Forms.Button
Friend WithEvents Station2 As System.Windows.Forms.Button
Friend WithEvents station3 As System.Windows.Forms.Button
Friend WithEvents AxMediaPlayer1 As AxMediaPlayer.AxMediaPlayer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.btnPower = New System.Windows.Forms.Button
Me.btnScan = New System.Windows.Forms.Button
Me.lblStationInfo = New System.Windows.Forms.Label
Me.TckbarVolume = New System.Windows.Forms.TrackBar
Me.radiobtnAM = New System.Windows.Forms.RadioButton
Me.radiobtnFM = New System.Windows.Forms.RadioButton
Me.btnMute = New System.Windows.Forms.Button
Me.Station1 = New System.Windows.Forms.Button
Me.Station2 = New System.Windows.Forms.Button
Me.station3 = New System.Windows.Forms.Button
Me.AxMediaPlayer1 = New AxMediaPlayer.AxMediaPlayer
CType(Me.TckbarVolume, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.AxMediaPlayer1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'btnPower
'
Me.btnPower.Location = New System.Drawing.Point(24, 24)
Me.btnPower.Name = "btnPower"
Me.btnPower.Size = New System.Drawing.Size(56, 24)
Me.btnPower.TabIndex = 0
Me.btnPower.Text = "0/I"
'
'btnScan
'
Me.btnScan.Location = New System.Drawing.Point(424, 24)
Me.btnScan.Name = "btnScan"
Me.btnScan.Size = New System.Drawing.Size(72, 24)
Me.btnScan.TabIndex = 1
Me.btnScan.Text = "Scan"
'
'lblStationInfo
'
Me.lblStationInfo.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.lblStationInfo.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblStationInfo.Location = New System.Drawing.Point(120, 24)
Me.lblStationInfo.Name = "lblStationInfo"
Me.lblStationInfo.Size = New System.Drawing.Size(264, 48)
Me.lblStationInfo.TabIndex = 2
Me.lblStationInfo.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'TckbarVolume
'
Me.TckbarVolume.Location = New System.Drawing.Point(648, 208)
Me.TckbarVolume.Maximum = 20
Me.TckbarVolume.Name = "TckbarVolume"
Me.TckbarVolume.Size = New System.Drawing.Size(168, 45)
Me.TckbarVolume.TabIndex = 3
'
'radiobtnAM
'
Me.radiobtnAM.Checked = True
Me.radiobtnAM.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.radiobtnAM.Location = New System.Drawing.Point(40, 104)
Me.radiobtnAM.Name = "radiobtnAM"
Me.radiobtnAM.Size = New System.Drawing.Size(40, 16)
Me.radiobtnAM.TabIndex = 5
Me.radiobtnAM.TabStop = True
Me.radiobtnAM.Text = "AM"
'
'radiobtnFM
'
Me.radiobtnFM.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.radiobtnFM.Location = New System.Drawing.Point(120, 104)
Me.radiobtnFM.Name = "radiobtnFM"
Me.radiobtnFM.Size = New System.Drawing.Size(40, 16)
Me.radiobtnFM.TabIndex = 6
Me.radiobtnFM.Text = "FM"
'
'btnMute
'
Me.btnMute.Image = CType(resources.GetObject("btnMute.Image"), System.Drawing.Image)
Me.btnMute.Location = New System.Drawing.Point(568, 208)
Me.btnMute.Name = "btnMute"
Me.btnMute.Size = New System.Drawing.Size(64, 48)
Me.btnMute.TabIndex = 8
'
'Station1
'
Me.Station1.Location = New System.Drawing.Point(584, 24)
Me.Station1.Name = "Station1"
Me.Station1.Size = New System.Drawing.Size(32, 24)
Me.Station1.TabIndex = 9
Me.Station1.Text = "1"
'
'Station2
'
Me.Station2.Location = New System.Drawing.Point(640, 24)
Me.Station2.Name = "Station2"
Me.Station2.Size = New System.Drawing.Size(32, 24)
Me.Station2.TabIndex = 10
Me.Station2.Text = "2"
'
'station3
'
Me.station3.Location = New System.Drawing.Point(696, 24)
Me.station3.Name = "station3"
Me.station3.Size = New System.Drawing.Size(32, 24)
Me.station3.TabIndex = 11
Me.station3.Text = "3"
'
'AxMediaPlayer1
'
Me.AxMediaPlayer1.Location = New System.Drawing.Point(240, 240)
Me.AxMediaPlayer1.Name = "AxMediaPlayer1"
Me.AxMediaPlayer1.OcxState = CType(resources.GetObject("AxMediaPlayer1.OcxState"), System.Windows.Forms.AxHost.State)
Me.AxMediaPlayer1.Size = New System.Drawing.Size(240, 56)
Me.AxMediaPlayer1.TabIndex = 12
Me.AxMediaPlayer1.Visible = False
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(840, 270)
Me.Controls.Add(Me.AxMediaPlayer1)
Me.Controls.Add(Me.station3)
Me.Controls.Add(Me.Station2)
Me.Controls.Add(Me.Station1)
Me.Controls.Add(Me.btnMute)
Me.Controls.Add(Me.radiobtnFM)
Me.Controls.Add(Me.radiobtnAM)
Me.Controls.Add(Me.TckbarVolume)
Me.Controls.Add(Me.lblStationInfo)
Me.Controls.Add(Me.btnScan)
Me.Controls.Add(Me.btnPower)
Me.Name = "Form1"
Me.Text = "PC Radio"
CType(Me.TckbarVolume, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.AxMediaPlayer1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btnPower_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPower.Click
If Mode = ModeEnum.OffMode Then
Mode = ModeEnum.OnMode
AxMediaPlayer1.FileName = "c:\cwmusic\ChrisBrown.mp3"
Else
Mode = ModeEnum.OffMode
AxMediaPlayer1.Stop()
Dim sw As New IO.StreamWriter("c:\lastStation.txt")
sw.Write(radioStations(0).ToString)
sw.Close()
End If
SetMode(Me, Mode)
End Sub
Dim radioStations(19) As Station
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
AxMediaPlayer1.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
radioStations(0) = New Station("Classic Rock", "http://www.cfm.com", RadioBand.FM)
radioStations(0).SongName = "c:\cwmusic\Kylie.mp3"
radioStations(1) = New Station("Carly's Test", "http://www.cfm.com", RadioBand.AM)
radioStations(1).SongName = "c:\cwmusic\Snowpatrol.mp3"
radioStations(2) = New Station("Carly's Test Station2", "http://www.cfm.com", RadioBand.FM)
radioStations(2).SongName = "c:\cwmusic\Kylie.mp3"
End Sub
Private Sub btnScan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScan.Click
AxMediaPlayer1.Mute = True
Dim oForm As New Form2
oForm.ShowDialog()
AxMediaPlayer1.Mute = False
End Sub
Private Sub btnMute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMute.Click
If AxMediaPlayer1.Mute Then
AxMediaPlayer1.Mute = False
Else
AxMediaPlayer1.Mute = True
End If
End Sub
Private Sub radiobtnAM_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radiobtnAM.CheckedChanged
If radiobtnAM.Checked Then
Module1.AM = True
Else
Module1.AM = False
End If
End Sub
Private Sub radiobtnFM_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles radiobtnFM.CheckedChanged
If radiobtnFM.Checked Then
Module1.AM = False
Else
Module1.AM = True
End If
End Sub
Private Sub Station1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Station1.Click
AxMediaPlayer1.FileName = "c:\cwmusic\Ronan.mp3"
lblStationInfo.Text = radioStations(0).ToString()
End Sub
Private Sub Station2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Station2.Click
AxMediaPlayer1.FileName = "c:\cwmusic\Snowpatrol.mp3"
lblStationInfo.Text = radioStations(1).ToString()
End Sub
Private Sub station3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles station3.Click
AxMediaPlayer1.FileName = "c:\cwmusic\Kylie.mp3"
lblStationInfo.Text = radioStations(2).ToString()
End Sub
Public Class Station
Private InfoText As String
Private URL As String
Private Band As RadioBand
Private song As String
Public Sub New()
End Sub
Public Sub New(ByVal InfoText As String, _
ByVal URL As String, _
ByVal Band As RadioBand)
Me.InfoText = InfoText
Me.URL = URL
Me.Band = Band
End Sub
Public Property SongName()
Get
Return song
End Get
Set(ByVal value)
song = value
End Set
End Property
Public Overrides Function ToString() As String
Return Me.InfoText
End Function
End Class
Public Enum RadioBand
FM = 0
AM = 1
End Enum
End Class