i have a windows media player in c# windows form and now i want this player to play a audio file of which the location i provide...and i should be able to control the media player components like play,forward,rewind,stop........ please someone help for this as soon as possible...

Dani AI

Generated

As pointed to the MSDN tutorial, here is a short, practical summary to get a Windows Forms media player working for . Add the Windows Media Player COM control to the Toolbox (Choose Items... -> COM Components -> Windows Media Player) and drag it onto your form. Visual Studio will create an AxWindowsMediaPlayer instance; you can set a file path to its URL property and use its Ctlcontrols and settings members to control playback.

Example usage:

axWindowsMediaPlayer1.URL = @"C:\Music\song.mp3";
axWindowsMediaPlayer1.Ctlcontrols.play();
axWindowsMediaPlayer1.Ctlcontrols.pause();
axWindowsMediaPlayer1.Ctlcontrols.stop();
axWindowsMediaPlayer1.Ctlcontrols.currentPosition += 10;   // forward 10 seconds
axWindowsMediaPlayer1.Ctlcontrols.currentPosition -= 10;   // rewind 10 seconds
axWindowsMediaPlayer1.settings.volume = 75;                // 0-100

// monitor state changes
axWindowsMediaPlayer1.PlayStateChange += AxWindowsMediaPlayer1_PlayStateChange;

private void AxWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
    // e.newState corresponds to WMPLib.WMPPlayState values
}

Troubleshooting notes: use verbatim strings or escape backslashes for paths; verify the file exists and the system has the needed codecs; on Windows N/KN SKUs the Media Feature Pack is required for WMP; if the ActiveX control fails on a 64-bit machine, try compiling the app as x86. For web scenarios do not host this control server-side — use client-side HTML5 audio or an embedded player. For audio-only or advanced processing, consider a managed library such as NAudio.

Recommended Answers

All 2 Replies

thank u so much for ur reply.. i will try it now....
thanks a lot..

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.