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/

相关文章:

windows - 桌面路径的环境变量是什么?

windows - Microsoft nanoserver 未运行 exe 文件

c# - XAML Storyboard动画从外部视口(viewport)移动图像-Windows Phone 8

c# - 寻找有关使用高级套接字选项的说明和指南

c# - 我应该先构建一个字符串然后写入文件吗?

c# - EF : Create/Remove relation from Many-to-Many relations when `AutoDetectChangesEnabled` and `ProxyCreationEnabled` are disabled on DbContext

c# - 使用 RestSharp (C#) 向 aws 发出请求

php - 在 Windows 服务器上使用 mkdir 时权限被拒绝

c# - UserControl 属性绑定(bind)不更新 DataContext

c# - WPF 资源加载在 LoadFrom 加载上下文中失败