Rocky Balboa
Rocky Balboa

Reputation: 814

Error in Windows 8 phone app code for FIle Picker

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);


}
}
}
}

The code is of audio player and I want to pick files from storage. In above code following code generates error

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

Error is:- No overload for method 'SetSource' takes 2 arguments. can anyone help me with that? Plzz And also if any other mistake let me know about that.

Upvotes: 0

Views: 542

Answers (1)

Romasz
Romasz

Reputation: 29792

As MSDN for FileOpenPicker says:

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

EDIT

As ToniPetrina says there can be more issues regarding your code. I've pointed the one that will probably make impossible to do what you want. As it it also 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.

AFAIK it's very hard to copy files from MediaLibrary to IsolatedStorage. And I also would be grateful if someone had showed how to do it.

Upvotes: 3

Related Questions