c# - 文件选取器的 Windows 8 手机应用代码错误

标签 c# windows xaml windows-phone-8

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using PhoneApp4.Resources;
using Microsoft.Phone.Tasks;
using System.Windows.Media;
using System.Windows.Media.Animation;
using Windows.Storage.Pickers;
using Windows.Storage.FileProperties;
using System.IO;
using Windows.Storage;
using Windows.Storage.Streams;

namespace PhoneApp4
{
public partial class MainPage : PhoneApplicationPage
{

    public MainPage()
    {
        InitializeComponent();
    }
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        WebBrowserTask wbt = new WebBrowserTask();
        wbt.Uri = new Uri("http://www.facebook.com", UriKind.Absolute);
        wbt.Show();
    }

    private void Play_Click(object sender, RoutedEventArgs e)
    {

        medias.Play();

    }

    private void Pause_Click(object sender, RoutedEventArgs e)
    {

        medias.Pause();

    }

    private void Stop_Click(object sender, RoutedEventArgs e)
    {

        medias.Stop();
    }



        private async void Browse_Click(object sender, RoutedEventArgs e)
        {
            var openPicker = new FileOpenPicker();

     //     openPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;

            openPicker.FileTypeFilter.Add(".mp3");

            var file = await openPicker.PickSingleFileAsync();

            var stream = await file.OpenAsync(FileAccessMode.Read);
             stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);


  if (null != file)
 {
                medias.SetSource(stream, file.ContentType);


}
}
}
}

代码是音频播放器,我想从存储中选择文件。 在上面的代码中,以下代码会产生错误

if (null != file){  medias.SetSource(stream, file.ContentType); }  

错误是:- 方法“SetSource”的重载没有采用 2 个参数。 任何人都可以帮我吗?麻烦 如果有任何其他错误,请告诉我。

最佳答案

作为MSDN for FileOpenPicker说:

Windows Phone 8
This API is supported in native apps only.

编辑

正如 ToniPetrina 所说,您的代码可能存在更多问题。我已经指出了可能无法做你想做的事情。因为它也是mentioned here :

The FileOpenPicker in WP8 is simply a Windows Runtime wrapper over the same photo library functionality that's accessible from the managed PhotoChooserTask. We do not currently support choosing files other than photos or choosing files from other Store apps.

据我所知,很难将文件从 MediaLibrary 复制到 IsolatedStorage。如果有人展示了如何做,我也将不胜感激。

关于c# - 文件选取器的 Windows 8 手机应用代码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21548366/

相关文章:

c# - 例如,如何在C#的一行中获得多个输入(1 2 3 4 5)而不必一一输入

c# - 多个返回情况的有条件if

java - 如何在不使用 ping.exe 的情况下使用 Windows 上的 Java 一次发送多个 ping?

c# - 无法更改DataGrid中的前景

c# - 使用 MVVM Xamarin Forms 使用数据填充选择器

c# - Windows 10 中的触摸屏友好文件选择器

c# - 为什么接口(interface)不起作用,但抽象类可以使用泛型类约束?

c# - Task.Yield、Task.Run 和 ConfigureAwait(false) 之间有什么区别?

windows - Windows 批处理脚本中 SET/A 命令中使用的符号

windows - 如何让 emacs Zip-Archive 模式在 Windows 上工作