如何在C#中将文件.mp3导入url [英] How get file .mp3 into url in C#

查看:132
本文介绍了如何在C#中将文件.mp3导入url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的每个人,

当我有链接html时,我想播放音乐。我展示了具有文件音频的xml链接和搜索路径。但是对于不同的网络,我需要有一种方法来捕捉它的不同。那你能帮帮我吗?对我来说,一个可以捕获所有网络的解决方案。

非常感谢你! :)。



我尝试了什么:



这是一个方式,我抓住文件mp3:

私人字符串get_resource(字符串网址)

{

data_xml = null;

WebClient wc = new WebClient();

GZipStream responseStream = new GZipStream(wc.OpenRead(url),CompressionMode.Decompress);

StreamReader reader = new StreamReader( responseStream);

data_xml = reader.ReadToEnd();

返回data_xml;

}

Dear Everybody,
I want to play music when i have link html of it. I shown xml of link and search path which have file audio. But with a different web i need have a a way catch it differnt. So can you help me? for me a solution which can catch all web.
Thank you so much!!! :).

What I have tried:

this is a way, which i catch file mp3:
private string get_resource (string url)
{
data_xml = null;
WebClient wc = new WebClient();
GZipStream responseStream = new GZipStream(wc.OpenRead(url), CompressionMode.Decompress);
StreamReader reader = new StreamReader(responseStream);
data_xml = reader.ReadToEnd();
return data_xml;
}

推荐答案

从评论开始到你的问题,如果这是一个ASP.NET Web应用程序;既然你已经在HTML下标记了它,那么更好的选择是流媒体而不是推送URL中的媒体内容。在我看来,这是发送媒体文件最糟糕的方法。相反,我的建议是使用媒体流选项,在页面加载后提交文件,这样文档下载就没有延迟。



流媒体 - 维基百科,免费的百科全书 [< a href =https://en.wikipedia.org/wiki/Streaming_mediatarget =_ blanktitle =New Window> ^ ]



媒体流在这些情况下非常有用,您希望允许客户端收听在线内容。可用的库和框架已经支持从另一个位置下载内容; HTTP流式传输。事实上, < audio> [ ^ ]和 < video> [ ^ ]支持以后通过人机交互流媒体内容的选项。因为你在谈论.mp3文件;

Starting from the comment to your question, if this is an ASP.NET web application; since you have tagged it under HTML, then the better options are to stream the media instead of pushing the media content in the URL. Which, in my opinion is the worst method of sending the media file. Instead, my recommendation is using the media streaming options, to submit the file after the page had loaded, so that there is no delay in document downloading.

Streaming media - Wikipedia, the free encyclopedia[^]

Media streaming is very helpful in these cases, where you want to allow the clients to listen to the online content. The available libraries and frameworks already support to download the content from another location; HTTP streaming. Infact, the HTML elements of <audio>[^] and <video>[^] do support the options to stream the media content later with the human-interaction. Since you're talking about .mp3 files;
<audio src="http://location/to/file.mp3" preload="metadata">
   Browser doesn't support <code>audio</code> element.
</audio>



这只会加载元数据,但会在用户想要加载和播放数据时传输数据。



< audio> - HTML | MDN [ ^ ]

直播使用c#|在asp.net mvc中播放视频ASP.NET论坛 [ ^ ]

使用ASP.NET Web API异步流式传输视频| StrathWeb。一个自由流动的网络技术独白。 [ ^ ]



编辑



如果是Windows窗体应用程序,您可以在应用程序中嵌入Windows Media Player,然后将其源添加到存在文件的HTTP URL。这里有一个明确解释的方法,如何:嵌入Windows Media Player在表格上 [ ^ ]。但是,使用URL几乎没有意义。因为,如果您的文件在网上找到,您可以下载该文件。



还有另一种方法,有一个开源产品VLC媒体播放器,它还提供了一个可以在Windows中使用的对象的包装器表格申请。您可以使用该库来构建和呈现从HTTP资源流式传输媒体内容的对象。



LibVLC.NET - 主页 [ ^ ]


This would load the metadata only, but would stream the data once the user wants to load and play the data.

<audio> - HTML | MDN[^]
live video streaming in asp.net mvc using c# | The ASP.NET Forums[^]
Asynchronously streaming video with ASP.NET Web API | StrathWeb. A free flowing web tech monologue.[^]

Edit

In case of Windows Forms application, you can either embed a Windows Media Player in the application and then add its source to the HTTP URL, where your file is present. One way to do that is clearly explained here, How to: Embed Windows Media Player on a Form[^]. But then, using the URL makes very little sense. Because, if your file is found somewhere online, you can download the file.

There is yet another method of doing this, there is an open source product VLC media player, which also provides a wrapper around its objects that can be used in the Windows Forms application. You can use that library to build and render the objects that stream the media content from an HTTP resource.

LibVLC.NET - Home[^]


这篇关于如何在C#中将文件.mp3导入url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆