在Windows Phone 8的下载媒体文件的亲语法 [英] Downloading Media File pro-grammatically in Windows Phone 8

查看:105
本文介绍了在Windows Phone 8的下载媒体文件的亲语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用是视频/音频的基础应用,我们已经上传所有的媒体在Windows Azure上。

Our app is video/audio based app, and we have uploaded all the media on Windows Azure.

然而它需要以方便用户下载点播音频/视频文件,以使它们可以在本地玩。

However it is required to facilitate user to download audio/video file on demand, so that they can play it locally.

所以我需要下载音频/视频文件的亲语法并将其保存在IsolatedStorage。

So i need to download audio/video file pro-grammatically and save it in IsolatedStorage.

我们为每个音频/视频的Windows Azure媒体文件访问URL。但我被困在下载媒体文件的第1步。

We have Windows Azure Media File Access URLs for each audio/video. But I am stuck in 1st step of downloading media file.

我一派并在<少时href=\"http://www.c-sharpcorner.com/uploadfile/kirtan007/how-to-download-file-and-showing-its-progress-in-progress-bar/\">this文章,但对于Web客户端没有功能DownloadFileAsync,我可以使用。

I googled and came across this article, but for WebClient there is no function DownloadFileAsync that I can use.

不过我想它的其他功能DownloadStringAsyn和下载媒体文件是字符串格式,但不知道如何将其转换为音频(WMA)/视频(MP4)格式。请给我建议,我该怎么处理?是否有其他的方式来下载媒体​​文件?

However I tried its other function DownloadStringAsyn, and download media file is in string format but don't know how to convert it to audio(wma)/video(mp4) format. Please suggest me, how can I proceed? Is there other way to download media file?

下面是示例code,我用

Here is sample code that I used

private void ApplicationBarMenuItem_Click_1(object sender, EventArgs e)
    {
        WebClient mediaWC = new WebClient();
        mediaWC.DownloadProgressChanged += new DownloadProgressChangedEventHandler(mediaWC_DownloadProgressChanged);
        mediaWC.DownloadStringAsync(new Uri(link));            
        mediaWC.DownloadStringCompleted += new DownloadStringCompletedEventHandler(mediaWC_DownloadCompleted);           

    }

    private void mediaWC_DownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Cancelled)
            MessageBox.Show("Downloading is cancelled");
        else
        {
            MessageBox.Show("Downloaded");
        }
    }   

    private void mediaWC_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
        statusbar.Text = status= e.ProgressPercentage.ToString();
    }        

谢谢,
DK

Thanks, DK

推荐答案

在你的工具箱保存此:)

Save this in your toolbox :)

    public static Task<Stream> DownloadFile(Uri url)
    {
        var tcs = new TaskCompletionSource<Stream>();
        var wc = new WebClient();
        wc.OpenReadCompleted += (s, e) =>
        {
            if (e.Error != null) tcs.TrySetException(e.Error);
            else if (e.Cancelled) tcs.TrySetCanceled();
            else tcs.TrySetResult(e.Result);
        };
        wc.OpenReadAsync(url);
        return tcs.Task;
    }

这篇关于在Windows Phone 8的下载媒体文件的亲语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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