1
我有這樣的App.xaml.cs
:奇文件關聯處理錯誤
protected override void OnFileActivated(FileActivatedEventArgs args)
{
Window.Current.Content = new Frame();
((Frame)Window.Current.Content).Navigate(typeof(MainPage), args);
Window.Current.Activate();
}
這MainPage.xaml.cs
:
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
FileActivatedEventArgs filesArgs = (FileActivatedEventArgs)e.Parameter;
StorageFile file = (StorageFile)filesArgs.Files[0];
mc.SetSource(await file.OpenReadAsync(), file.ContentType);
mc.Play();
}
而這MainPage.xaml
:
<MediaElement x:Name="mc" />
現在,我面臨着一個很奇怪的問題。我已將我的應用程序與.MP4文件關聯。每當我打開任何文件,它都不會立即播放。例如。
- 我打開
a.mp4
,它不會播放,我不關閉應用程序。 - 我打開
b.mp4
,它不會播放,我不關閉應用程序。 - 然後,我打開
a.mp4
,它被播放。如果沒有,我會再試一次並播放它。現在,如果我打開任何MP4文件,直到我關閉該應用程序,它纔會毫無問題地播放。
所以,這個變通辦法有時:
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
FileActivatedEventArgs filesArgs = (FileActivatedEventArgs)e.Parameter;
StorageFile file = (StorageFile)filesArgs.Files[0];
StorageFile file2 = (StorageFile)filesArgs.Files[0];
mc.SetSource(await file2.OpenReadAsync(), file2.ContentType);
mc.SetSource(await file2.OpenReadAsync(), file2.ContentType);
mc.Play();
}
有誰知道爲什麼它也不是沒有解決辦法的工作?
@Programmer我在Core 2 Duo 6400上測試它。 –
@Programmer如果您通過從放置MediaElement的頁面調用FilePicker,我不認爲同樣的情況可以發生。 'MediaElement'在頁面的加載過程中被加載,當你打開'FilePicker'時頁面已經加載。它可能是一個錯誤,或者至少是一個無法記錄的功能。您可以嘗試在[MSDN論壇](http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp)上發佈該問題,那裏有更多來自微軟的人員。或者甚至可能在[Microsoft Connect](https://connect.microsoft.com/VisualStudio)上。 –
@Programmer你有沒有試過按照建議使用'MediaOpened'事件?它能解決你的問題嗎? –