Microsoft MAUI MediaElement FindResouce 无法识别资源文件

问题描述 投票:0回答:1

我已尝试了以下所有组合,但仍然没有为 MediaElement.FindResouce() 方法加载资源。

//onStartMusic.Source = MediaSource.FromUri("http://thinkingform.com/wp-content/uploads/2017/09/video-sample-mp4.mp4?_=1"); //this is working                     //onStartMusic.Source = MediaSource.FromUri("https://samplelib.com/lib/preview/mp3/sample-12s.mp3"); //this is working                     //onStartMusic.Source = MediaSource.FromResource("embed://onStart.mp3"); //made the music file as a embedded resource then also it did not worked.                     //onStartMusic.Source = MediaSource.FromResource("Resource://Raw/onStart.mp3");                     //onStartMusic.Source = MediaSource.FromResource("onStart.mp3"); //not loaded the music file                     //onStartMusic.Source = MediaSource.FromResource("resource://onStart.mp3"); //not loaded the music file                     //onStartMusic.Source = MediaSource.FromResource("resource://Resources/Raw/onStart.mp3"); //not loaded the music file                     //onStartMusic.Source = MediaSource.FromResource("resource://Flora.Resources.Raw.onStart.mp3");                     //onStartMusic.Source = MediaSource.FromResource("embed://Flora.Resources.Raw.onStart.mp3"); //not loaded the music file                     //onStartMusic.Source = MediaSource.FromFile("E:\\Trainings\\MAUI\\Flora\\Flora\\Resources\\Raw\\onStart.mp3"); //this is working                     //onStartMusic.Source = MediaSource.FromResource("Flora.Resources.Raw.onStart.mp3"); //not loaded the music file                     //onStartMusic.Source = MediaSource.FromResource("//Flora.Resources.Raw.onStart.mp3");  //not loaded the music file                     //onStartMusic.Source = MediaSource.FromResource("\\Flora.Resources.Raw.onStart.mp3"); //not loaded the music file                     //onStartMusic.Source = MediaSource.FromResource("resource:\\Flora.Resources.Raw.onStart.mp3"); //not loaded the music file                     //onStartMusic.Source = MediaSource.FromResource("Flora.Resources.Raw.onStart.mp3"); // After setting the file to embeded resource also not loaded the music file                     onStartMusic.Source = MediaSource.FromResource("embed://Flora.Resources.Raw.onStart.mp3"); //not loaded the music file                     onStartMusic.ShouldAutoPlay = true;                    onStartMusic.Play();
maui
1个回答
0
投票

如文档此处中所述。速记 URI 方案如 embed:// 仅当从 XAML 设置 Source 时才有效。

假设您的音频文件位于Resources/Raw/onStart.mp3中

然后确保音频文件的构建操作设置为

MauiAsset

然后下面的分配应该可以工作。文档中也提到了相同的内容。

onStartMusic.Source = MediaSource.FromResource("onStart.mp3");
    
© www.soinside.com 2019 - 2024. All rights reserved.