C# 文件选择器的Windows 8 phone应用程序代码出错
代码是音频播放器,我想从存储器中选择文件。 在上面的代码中,下面的代码生成错误C# 文件选择器的Windows 8 phone应用程序代码出错,c#,windows,xaml,windows-phone-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 M
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);
}
}
}
}
错误为:-方法“SetSource”没有重载包含2个参数。
有人能帮我吗?Plzz
如果还有其他错误,请告诉我。如所述:
Windows Phone 8此API仅在本机应用程序中受支持 编辑
正如ToniPetrina所说,您的代码可能存在更多问题。我已经指出了一个可能使你不可能做你想做的事的方法。因为它还: WP8中的FileOpenPicker只是一个Windows运行时包装器,它覆盖了可从托管PhotoChooserTask访问的相同照片库功能。我们目前不支持选择照片以外的文件或从其他商店应用程序中选择文件
另外,很难将文件从MediaLibrary复制到隔离存储。如果有人告诉我怎么做,我也会很感激。什么是
媒体类型?另外,您首先从哪里获得该代码?medias是我使用的媒体元素的名称。访问此站点您是否查看了MediaElement.SetSource
文档?似乎没有带这些参数的方法,如果该函数不存在,为什么要传递两个参数呢?请注意,您的链接是针对Windows 8的,而您要求的是Windows Phone 8。为什么?使用媒体元素?好吧,只要把小溪递给它,你就完了。另外,您不能在Windows Phone 8上使用文件选择器。这不是他(唯一)的问题。@ToniPetrina您是对的,可能还有更多的问题,我已经指出了一个问题,使OP不可能(AFAIK)做OP想要做的事。
if (null != file){ medias.SetSource(stream, file.ContentType); }