MediaSource.CreateFromUri() cannot retrieve the file.

jigyanshu 21 Reputation points
2020-12-09T05:27:54.647+00:00

Here is my code........

var mediaPlayer = new MediaPlayer();
mediaPlayer.IsLoopingEnabled = true;
var soundPath = "D:\Documents\comunit\WinCom\Phonemar\otCom\bin\x86\Debug\AppX\Assets\Sound\ringing_tone.mp3"
try
{
mediaPlayer.Source = MediaSource.CreateFromUri(new Uri(soundPath));
}
catch (FileNotFoundException fex)
{
System.Diagnostics.Debug.WriteLine("{0} : {1}", DateTime.Now.ToString(), fex.Message);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("{0} : {1}", DateTime.Now.ToString(), ex.Message);
}

Crashing error message - System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

This crash is happened rendering. Whats the problem with this? I am using mediaplayer for MediaPlayer.Source . How can I get proper MediaSource using my first method? Help me please.

Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,534 questions
0 comments No comments
{count} votes

Accepted answer
  1. Roy Li - MSFT 32,721 Reputation points Microsoft Vendor
    2020-12-09T07:38:04.54+00:00

    Hello,

    Welcome to Microsoft Q&A!

    Are you trying to play the mp3 file that you added to the Assets folder? If it is, then the issue is caused by your URI.
    You could not pass the file path parameter to CreateFromUri directly. In general, the Uri parameter is HTTP protocol address such as http://www.xxx.com/xxx/test.mp4. But you could assign some the file path with UWP file access URI scheme.
    If you want to access the Assets folder in your project, you could try to use the following Uri:

    var soundPath = "ms-appx:///Assets/xxxxxx/xxx.mp3";  
    

    Thank you.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Castorix31 82,661 Reputation points
    2020-12-09T08:01:44.5+00:00

    Use "\" in your path or @ :

    var soundPath = @"D:\Documents\comunit\WinCom\Phonemar\otCom\bin\x86\Debug\AppX\Assets\Sound\ringing_tone.mp3";
    
    0 comments No comments