【发布时间】:2014-02-04 09:23:32
【问题描述】:
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 个参数。 任何人都可以帮助我吗? PLZ 如果有任何其他错误,请告诉我。
【问题讨论】:
-
medias' 类型是什么?另外,您最初是从哪里获得该代码的? -
medias 是我使用的媒体元素的名称。访问此msdn.microsoft.com/en-us/library/windows/apps/hh871377.aspx
-
您查看过
MediaElement.SetSource文档吗? msdn.microsoft.com/en-us/library/… 似乎没有带参数的方法,如果该函数不存在,为什么要传递两个参数 -
另请注意,您的链接适用于 Windows 8,而您要求的是 Windows Phone 8。
-
为了什么?使用媒体元素?好吧,只需将流传递给它,你就完成了。此外,您不能在 Windows Phone 8 上使用文件选择器。
标签: c# windows xaml windows-phone-8