如果源文件来自FileActivatedEventArgs,则播放失败 [英] Playback fails if source file is taken from FileActivatedEventArgs

查看:60
本文介绍了如果源文件来自FileActivatedEventArgs,则播放失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我的音频播放器存在以下问题。我希望它是某些音频文件(例如mp3)的默认应用程序。为此,我声明了文件类型关联(支持的文件类型:
.mp3 ,可执行文件: myAppName.exe ,入口点:  myAppName。应用)。 

I have following problem with my audio player. I would like it to be a default app for some audio files (e.g. mp3). For that purpose I declared File Type Associations (Supported File Type: .mp3, Executable: myAppName.exe, Entry Point: myAppName.App). 

App.xaml.cs 文件包含 OnFileAcitvated 方法的以下定义:

App.xaml.cs file contains following definition for OnFileAcitvated method:

        protected override void OnFileActivated(FileActivatedEventArgs args)

        {

            var rootFrame = new Frame();

            rootFrame.Navigate(typeof(BlankPage));

            Window.Current.Content = rootFrame;

            BlankPage p = rootFrame.Content as BlankPage;

            p.SetFileToPlay(args.Files [0] as StorageFile);

            Window.Current.Activate();

        BlankPage.xaml.cs 文件中的

        protected override void OnFileActivated(FileActivatedEventArgs args)
        {
            var rootFrame = new Frame();
            rootFrame.Navigate(typeof(BlankPage));
            Window.Current.Content = rootFrame;
            BlankPage p = rootFrame.Content as BlankPage;
            p.SetFileToPlay(args.Files[0] as StorageFile);
            Window.Current.Activate();
        }

SetFileToPlay 方法定义如下:

        public async void SetFileToPlay(StorageFile fileToPlay)

        {

            IRandomAccessStream stream = await fileToPlay.OpenAsync(FileAccessMode.Read);

            player.SetSource(stream,fileToPlay.ContentType);

            player.Play();

            MediaControl.IsPlaying = true;

        public async void SetFileToPlay(StorageFile fileToPlay)
        {
            IRandomAccessStream stream = await fileToPlay.OpenAsync(FileAccessMode.Read);
            player.SetSource(stream, fileToPlay.ContentType);
            player.Play();
            MediaControl.IsPlaying = true;

       }

       }

当然它不起作用。我不明白为什么。 

And of course it doesn't work. I have no idea why. 

我在这里读到它( http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh779669.aspx ),查看MSDN示例(关联启动示例),检查
示例( http://tozon.info/blog/post/2011/10/11/Windows-8-Metro-declarations-File-Type-Associations.aspx )我仍然遇到问题。

I read about it here (http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh779669.aspx), check MSDN example (Association launching sample), examine that example (http://tozon.info/blog/post/2011/10/11/Windows-8-Metro-declarations-File-Type-Associations.aspx) and still I have a problem with it.

另一方面,如果我将SetFileToPlay方法更改为使用 FileOpenPickier

On the other hand, if I change SetFileToPlay method to use FileOpenPickier:

然后效果很好。

那么......我做错了什么?

So... what I do wrong?

我的结论和意见如下

1。从FileActivatedEventArgs获取StorageFile不会引发MediaOpened事件(对于FileOpenPicker,它会被引发)

1. Obtaining StorageFile from FileActivatedEventArgs doesn't raise MediaOpened event (for FileOpenPicker it is raised)

2。我可以通过  FileActivatedEventArgs读取文件的名称,因此似乎获得了文件,但是开始播放时出现问题

2. I can read the name of the file that is read via FileActivatedEventArgs, so it seems that file is obtained, but there is problem to start playback

3 。如果我在FileActivatedEventArgs的player.SetSource之后检查了player.CurrentState,那么它被设置为
Openning ,所以这似乎是个问题。

3. if I check player.CurrentState after player.SetSource for FileActivatedEventArgs case, then it is set to Openning, so it seems to be a problem there.

4。如果不是从FileOpenPicker类中获取,则无法设置播放器源文件。

4. It is not possible to set player source file if it is not taken from FileOpenPicker class.

任何有用的想法?

推荐答案

您的问题:

1)文件失败时是否有任何例外情况玩吗? 

Questions for you:
1) Are there any exceptions at all when the file fails to play? 

2)如果您尝试从文档和/或音乐库中打开文件,并且您已经提供了文档库/音乐库功能,结果是否有所不同?

2) If you try to open a file from the Documents and/or Music library, and you have give the Documents Library/Music Library capabilities, is the outcome any different?

3)如果您要将文件类型更改为.jpg并尝试打开该文件并显示它,那么结果会不同?

3) If you were to change the file type to .jpg and try to open that file and display it, is the outcome for that any different?

这篇关于如果源文件来自FileActivatedEventArgs,则播放失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆