0

Currently I had developed Windows 10 Mobile Apps that can play sounds/audio functions. When I write this statement to play the audio/sounds , it will display the error when the Image Tapped event is Tapped. The Source code as below:

MediaElement mysong = new MediaElement();

        try
        {
            var folder = await StorageFolder.GetFolderFromPathAsync(@"ms-appx://Assets/Media/");
            if (folder != null)
            {
                var file = await folder.GetFileAsync("police_alarm.mp3");
                if (file != null)
                {
                    var stream = await file.OpenReadAsync();
                    mysong.SetSource(stream, file.ContentType);
                    mysong.Volume = 100;
                    mysong.Play();
                }
            }
            else
            {
                MessageDialog dialog = new MessageDialog("Siren can't play !!! Please keep yourself safe !!!", "Error");
                await dialog.ShowAsync();
            }
        }
        catch(Exception ex)
        {
            MessageDialog dialog = new MessageDialog(ex.ToString(), "Error");
            await dialog.ShowAsync();
        }

The Error System Exception : The Specified path is invalid

is that any solutions for this?

Thank You.

2
  • what is the error? Commented Aug 14, 2017 at 12:35
  • @KenTucker the error "System Exception : The Specified path is invalid" . Thank You. Commented Aug 14, 2017 at 12:38

1 Answer 1

1

The problem is that you have used wrong folder path.

var folder = await StorageFolder.GetFolderFromPathAsync(@"ms-appx://Assets/Media/");

Please use the following code to replace your folder path.

string root = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;
string path = root + @"\Assets\Media";
var folder = await StorageFolder.GetFolderFromPathAsync(path);

For more you could refer to File access permissions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.