Member Avatar for Member #925360

Alright, I have a Form with a Media Player in it. Which plays a Song.

AxWindowsMediaPlayer1.URL = My.Computer.FileSystem.CurrentDirectory & "\Music.mp3"
AxWindowsMediaPlayer1.Ctlcontrols.play()
AxWindowsMediaPlayer1.settings.playCount = 999
Me.Opacity = 0

It's playing in the background since the Form is hidden.
When I play it in Debug, everything works fine.
When I run the app outside Debug, I get this error:
The Music File is there, but strangely, there comes this weird error.

Dani AI

Generated

nailed the symptom and 's try/catch is useful while debugging, but the root cause is how the COM/ActiveX interop assemblies are generated and deployed. The wrappers (Interop.WMPLib.dll and AxInterop.WMPLib.dll) are created by Visual Studio when the Windows Media Player control is added to a form; they must be produced and shipped with the Release build rather than manually dropping random DLLs into folders.

Steps to fix and to recover deleted Ax files:

  • Remove any manually added AxInterop/Interop references (they can create the "ambiguous" type conflict).
  • Re-add the control properly: Toolbox → right‑click → Choose Items → COM Components → check "Windows Media Player", then drag the control onto your form. Build the project — Visual Studio will regenerate the Ax/Interop assemblies automatically.
  • In Solution Explorer, select the generated references and set Copy Local = True and Embed Interop Types = False. This makes sure the interop DLLs end up next to your EXE for both Debug and Release.

Other important notes:

  • Set the project platform to x86 (Project Properties → Compile/Build → Platform target) to avoid ActiveX bitness mismatches on many dev/test systems.
  • After a Release build, confirm the two interop DLLs appear in bin\Release next to the EXE before distributing.

A small, safer way to load the file at runtime:

Dim mp3 = IO.Path.Combine(Application.StartupPath, "Music.mp3")
If IO.File.Exists(mp3) Then
    AxWindowsMediaPlayer1.URL = mp3
Else
    Debug.WriteLine("Missing file: " & mp3)
End If

Run the EXE directly from the Release folder while testing deployment; if errors persist, remove duplicate refs and rebuild, and ensure Windows Media Player is present on the target machine.

Recommended Answers

All 4 Replies

Member Avatar for Member #925360

I tried to add a Reference (Axinterop.wmpLib.dll) but now I get this Error: "AxWindowsMediaPlayer" is ambiguous in the namespace "AxWMPLib"

Member Avatar for Member #925360

I deleted all the Files that have to do with Ax....now I don't get them back....please help me. I am desperated.

Start a new.project, add your wmp(WindowsMediaPlayer) to Form, Then modify code w/this.

Try
            '// wmp.code here.
        Catch ex As Exception
            MsgBox(ex.Message) '// displays error.msg and does not crash app.  error.msg is not necessarly needed.
        End Try

If you get an error.msg, post the result.

Member Avatar for Member #925360

I found out what the problem was. It runs fine in the Debug, because the DLL Files are there.
If you move the .exe outside Debug, it's missing the DLL's, so it will give you an error.
SOLUTION: Paste the DLL's into the same directory where the .exe is located.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.