如何播放视频文件?

发布于 2024-08-19 11:52:04 字数 1539 浏览 6 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半仙 2024-08-26 11:52:04

您应该能够使用媒体播放器控件来播放媒体文件。

http://msdn.microsoft.com 播放音频的示例/en-us/library/dd562692(VS.85).aspx,您应该能够将其调整为视频:

// [ C# ]
WMPLib.WindowsMediaPlayer Player;

private void PlayFile(String url)
{
    Player = new WMPLib.WindowsMediaPlayer();
    Player.PlayStateChange += 
        new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(Player_PlayStateChange);
    Player.MediaError += 
        new WMPLib._WMPOCXEvents_MediaErrorEventHandler(Player_MediaError);
    Player.URL = url;
    Player.controls.play();
}

private void Form1_Load(object sender, System.EventArgs e)
{
    // TODO  Insert a valid path in the line below.
    PlayFile(@"c:\myaudio.wma");
}

private void Player_PlayStateChange(int NewState)
{
    if ((WMPLib.WMPPlayState)NewState == WMPLib.WMPPlayState.wmppsStopped)
    {
        this.Close();
    }
}

private void Player_MediaError(object pMediaObject)
{
    MessageBox.Show("Cannot play media file.");
    this.Close();
}

MSDN 上提供了更多信息,网址为 http://msdn.microsoft.com/en-us/library/dd564582(VS.85).aspx< /a>

You should be able to use the Media Player control to play media files.

Example of playing audio from http://msdn.microsoft.com/en-us/library/dd562692(VS.85).aspx, you should be able to adapt it to video:

// [ C# ]
WMPLib.WindowsMediaPlayer Player;

private void PlayFile(String url)
{
    Player = new WMPLib.WindowsMediaPlayer();
    Player.PlayStateChange += 
        new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(Player_PlayStateChange);
    Player.MediaError += 
        new WMPLib._WMPOCXEvents_MediaErrorEventHandler(Player_MediaError);
    Player.URL = url;
    Player.controls.play();
}

private void Form1_Load(object sender, System.EventArgs e)
{
    // TODO  Insert a valid path in the line below.
    PlayFile(@"c:\myaudio.wma");
}

private void Player_PlayStateChange(int NewState)
{
    if ((WMPLib.WMPPlayState)NewState == WMPLib.WMPPlayState.wmppsStopped)
    {
        this.Close();
    }
}

private void Player_MediaError(object pMediaObject)
{
    MessageBox.Show("Cannot play media file.");
    this.Close();
}

There's a bit more information available on MSDN at http://msdn.microsoft.com/en-us/library/dd564582(VS.85).aspx

著墨染雨君画夕 2024-08-26 11:52:04

您可以考虑使用 Managed DirectX 中的音频/视频控件作为快速解决方案:

http://msdn.microsoft.com/en-us/library/bb324497%28VS.85%29.aspx#dx_avp_playing_a_video_file

如果您需要对视频进行更多控制,或者更好地与在您的应用程序中,您可以使用 DirectShow。有一个很好的 C# 互操作库可用于访问它 (DirectShowLib)。

使用 DirectShow 的另一个优点是 Windows 将处理加载给定媒体类型所需的编解码器和渲染组件。

You might consider using the Audio/Video controls in Managed DirectX as a quick solution:

http://msdn.microsoft.com/en-us/library/bb324497%28VS.85%29.aspx#dx_avp_playing_a_video_file

If you need more control over the video, or better integration with your application, you can use DirectShow. There is a good C# interop library for accessing it (DirectShowLib).

One other plus of using DirectShow is that windows will handle loading the necessary codecs and rendering components necessary for a given media type.

北斗星光 2024-08-26 11:52:04

您始终可以使用 Silverlight 来显示视频内容,然后将 silverlight 应用程序插入您的网页。

以下是有关在 silverlight 中创建视频播放器的一些文章:

http://www.85turns.com/2008/04/02/create-a-video-player-silverlight-2-part-1/

http://weblogs.asp.net/dwahlin /archive/2008/03/07/silverlight-2-0-video-tutorials.aspx

You could always use Silverlight to show video content and then plug the silverlight application into your web page.

What follows are some articles on creating a video player in silverlight:

http://www.85turns.com/2008/04/02/create-a-video-player-silverlight-2-part-1/

or

http://weblogs.asp.net/dwahlin/archive/2008/03/07/silverlight-2-0-video-tutorials.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文