我可以帮助您使用AxWindowsMediaPlayer播放音频文件。
我正在使用Visual Basic.net 2012 Ultimate。
这是我的代码:
Imports AxWMPLib
Public Class Form1
Public WithEvents MediaPlayerObject As AxWindowsMediaPlayer = New AxWindowsMediaPlayer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MediaPlayerObject = New AxWindowsMediaPlayer
MediaPlayerObject.Ctlenabled = True
MediaPlayerObject.URL = "C:\Users\Simon\Music\Music\CanLucidDream\108761__soundbytez__birds-late-morning.wav"
MediaPlayerObject.Ctlcontrols.play()
End Sub
结束班
尝试访问任何对象属性或方法时出现以下错误:
AxInterop.WMPLib.dll中出现未处理的“System.Windows.Forms.AxHost.InvalidActiveXStateException”类型异常
答案 0 :(得分:0)
你需要注意
-MediaPlayerObject.URL = "C:\Users\Simon\Music\Music\CanLucidDream\108761__soundbytez__birds-late-morning.wav"-
应该是这样的;
MediaPlayerObject.URL = "C:\\\Users\\\Simon\\\Music\\\Music\\\CanLucidDream\\\108761__soundbytez__birds-late-morning.wav"
或者像这样;
MediaPlayerObject.URL = @"C:\Users\Simon\Music\Music\CanLucidDream\108761__soundbytez__birds-late-morning.wav"
答案 1 :(得分:-1)
在使用任何属性或方法之前,需要调用BeginInit()和EndInit()。
MediaPlayerObject.BeginInit()
MediaPlayerObject.EndInit()
MediaPlayerObject.CtlEnabled = True