为什么此代码段不起作用?(Uwp应用程序内容可播放媒体内容)

MarcAnt01

这是我的代码,我从MSDN论坛(https://social.msdn.microsoft.com/Forums/ie/en-US/ddb1b7f1-e988-40c7-8e1e-eaf6d8573ec2/uwp-how-to -play-sound-from-wav-fileresource?forum = wpdevelop)。

private DispatcherTimer timer;
        private TimeSpan myTime = new TimeSpan(0, 0, 60);

        public MainPage()
        {
            this.InitializeComponent();
            timer = new DispatcherTimer();
            timer.Interval = new TimeSpan(0, 0, 1);
            timer.Tick += Timer_Tick;
            timer.Start();
        }

        private void Timer_Tick(Object sender, object e)
        {

            if (myTime.Seconds > 0)
            {
                myTime -= new TimeSpan(0, 0, 1);
                MainTextBlock.Text = myTime.ToString();
            }
            else
            {
                timer.Stop();
                MainTextBlock.Text = "Finished";
                PlaySound_Async();
            }
        }

        private async void PlaySound_Async()
        {
            MediaElement timesup = new MediaElement();
            Windows.Storage.StorageFolder folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");
            Windows.Storage.StorageFile file = await folder.GetFileAsync("timesup.mp3");
            var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
            timesup.SetSource(stream, file.ContentType);
            timesup.Play();
        }

这是一个例外,我得到了这个例外,我已经将文件添加到了正确的文件夹中 资产文件夹

例外

延谷-MSFT

Just adding files to the Assets folder in File Explorer is not a complete step of importing file into the project. You also need to add the file to the Assets in the Solution Explorer of Visual Studio. You can check the following steps to import the file:

  1. Click Show All Files option in the Solution Explorer, and find the timesup.mp3 file in the Assets folder.

解决方案资源管理器

  1. Right click the timesup.mp3 file and select the Include In Project option.

上下文菜单

  1. Click the timesup.mp3 file and ensure the Build Action is set to Content in the Properties window.

属性窗口

除了使用上述步骤将文件导入到之外Assets,您还可以右键单击Assets并选择添加>现有项…,选择目标文件,然后单击Add按钮以导入文件。

此外,如果您想了解如何查看文件夹变量的输出,请参阅文档

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么此代码不起作用?man子手

来自分类Dev

为什么此shell代码不起作用?

来自分类Dev

为什么应用程序级资源不起作用

来自分类Dev

为什么离线Web应用程序不起作用?

来自分类Dev

为什么此代码段在VS 2013中不起作用?

来自分类Dev

为什么此C预处理程序代码不起作用?

来自分类Dev

为什么此块读取代码不起作用?

来自分类Dev

为什么此索引选择代码不起作用?

来自分类Dev

为什么此json交换代码不起作用?

来自分类Dev

近似Pi-为什么此代码不起作用?

来自分类Dev

为什么此八度代码不起作用?

来自分类Dev

使用媒体插件播放mp3的Phonegap应用程序不起作用

来自分类Dev

为什么此SwiftUI Picker代码不起作用?

来自分类Dev

为什么xmllint在Aurelia应用程序中不起作用但在普通JS应用程序中起作用

来自分类Dev

为什么此C代码在JavaScript中不起作用?

来自分类Dev

为什么这个简单的JavaScript代码段不起作用

来自分类Dev

为什么此代码不起作用(基本)

来自分类Dev

为什么此代码不起作用?C ++

来自分类Dev

String.Format:为什么此代码不起作用?

来自分类Dev

为什么此GridBagLayout代码不起作用?

来自分类Dev

为什么脱机Web应用程序不起作用?

来自分类Dev

为什么此代码段在VS 2013中不起作用?

来自分类Dev

为什么此SFML C ++代码不起作用?

来自分类Dev

为什么此代码不起作用?

来自分类Dev

为什么此Angular应用程序的第二部分不起作用?

来自分类Dev

为什么此代码段在我的VS2012中不起作用

来自分类Dev

为什么以下 bash 代码段不起作用?

来自分类Dev

从 Qt 到 UWP 应用程序的 PostMessage 不起作用

来自分类Dev

UWP:为什么这个执行别名不起作用?该应用程序卡在启动画面上

Related 相关文章

  1. 1

    为什么此代码不起作用?man子手

  2. 2

    为什么此shell代码不起作用?

  3. 3

    为什么应用程序级资源不起作用

  4. 4

    为什么离线Web应用程序不起作用?

  5. 5

    为什么此代码段在VS 2013中不起作用?

  6. 6

    为什么此C预处理程序代码不起作用?

  7. 7

    为什么此块读取代码不起作用?

  8. 8

    为什么此索引选择代码不起作用?

  9. 9

    为什么此json交换代码不起作用?

  10. 10

    近似Pi-为什么此代码不起作用?

  11. 11

    为什么此八度代码不起作用?

  12. 12

    使用媒体插件播放mp3的Phonegap应用程序不起作用

  13. 13

    为什么此SwiftUI Picker代码不起作用?

  14. 14

    为什么xmllint在Aurelia应用程序中不起作用但在普通JS应用程序中起作用

  15. 15

    为什么此C代码在JavaScript中不起作用?

  16. 16

    为什么这个简单的JavaScript代码段不起作用

  17. 17

    为什么此代码不起作用(基本)

  18. 18

    为什么此代码不起作用?C ++

  19. 19

    String.Format:为什么此代码不起作用?

  20. 20

    为什么此GridBagLayout代码不起作用?

  21. 21

    为什么脱机Web应用程序不起作用?

  22. 22

    为什么此代码段在VS 2013中不起作用?

  23. 23

    为什么此SFML C ++代码不起作用?

  24. 24

    为什么此代码不起作用?

  25. 25

    为什么此Angular应用程序的第二部分不起作用?

  26. 26

    为什么此代码段在我的VS2012中不起作用

  27. 27

    为什么以下 bash 代码段不起作用?

  28. 28

    从 Qt 到 UWP 应用程序的 PostMessage 不起作用

  29. 29

    UWP:为什么这个执行别名不起作用?该应用程序卡在启动画面上

热门标签

归档