简体   繁体   English

如何从.NET应用程序启动默认媒体播放器?

[英]How can I launch the default media player from a .NET application?

I need to launch a media file from a URL from within my c# .NET application. 我需要从我的c#.NET应用程序中的URL启动媒体文件。 Is there any way to do this natively in .NET? 有没有办法在.NET中本地执行此操作? I don't need an embedded player, I just need the default player to launch. 我不需要嵌入式播放器,我只需要默认播放器即可启动。 I have tried 我努力了

System.Diagnostics.Process.Start("File URL");

but it launches the default browser and downloads the file, instead of attempting to play it in WMP/VLC/whatever the default media player is. 但它会启动默认浏览器并下载文件,而不是尝试在WMP / VLC中播放它/无论默认媒体播放器是什么。 Any ideas? 有任何想法吗?

If you enter an URL it will be handled with the program registered to that URL format, in your case the default web browser. 如果输入URL,将使用注册为该URL格式的程序处理,在您的情况下是默认Web浏览器。

What format are the media in? 媒体的格式是什么? You can get associated program for an extension and then run that program with the url as parameter. 您可以获取扩展的关联程序,然后使用url作为参数运行该程序。 See: Windows: List and Launch applications associated with an extension 请参阅: Windows:与扩展程序关联的列表和启动应用程序

So if your media is for example .MP3, then find the assoicated program for .MP3 (using the code in the link above) and pass the url as a parameter to that program. 因此,如果你的媒体是例如.MP3,那么找到.MP3的联合程序(使用上面链接中的代码)并将url作为参数传递给该程序。

Another way to handle this is to temporary download the file to the local file system and then run your 处理此问题的另一种方法是临时将文件下载到本地文件系统,然后运行您的

System.Diagnostics.Process.Start("Local File");

Then it should work as you expect. 然后它应该按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM