Пример #1
0
        /// <summary>
        /// Handler for the system transport controls button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void SystemMediaControls_ButtonPressed(SystemMediaTransportControls sender, SystemMediaTransportControlsButtonPressedEventArgs e)
        {
            switch (e.Button)
            {
            case SystemMediaTransportControlsButton.Play:
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Scenario2MediaElement.Play();
                });

                break;

            case SystemMediaTransportControlsButton.Pause:
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Scenario2MediaElement.Pause();
                });

                break;

            case SystemMediaTransportControlsButton.Stop:
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Scenario2MediaElement.Stop();
                });

                break;

            default:
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// Click handler for the "Select a media file" button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void OpenFileButton_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker fileOpenPicker = new FileOpenPicker();

            // Filter to include a sample subset of file types
            fileOpenPicker.FileTypeFilter.Add(".wmv");
            fileOpenPicker.FileTypeFilter.Add(".mp4");
            fileOpenPicker.FileTypeFilter.Add(".mp3");
            fileOpenPicker.FileTypeFilter.Add(".wma");
            fileOpenPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;

            // Prompt user to select a file
            StorageFile file = await fileOpenPicker.PickSingleFileAsync();

            // Ensure a file was selected
            if (file != null)
            {
                if (systemMediaControls != null)
                {
                    MediaPlaybackType mediaPlaybackType;
                    if ((file.FileType == ".mp4") || (file.FileType == ".wmv"))
                    {
                        mediaPlaybackType = MediaPlaybackType.Video;
                    }
                    else
                    {
                        mediaPlaybackType = MediaPlaybackType.Music;
                    }

                    // Inform the system transport controls of the media information
                    if (!(await systemMediaControls.DisplayUpdater.CopyFromFileAsync(mediaPlaybackType, file)))
                    {
                        //  Problem extracting metadata- just clear everything
                        systemMediaControls.DisplayUpdater.ClearAll();
                    }
                    systemMediaControls.DisplayUpdater.Update();
                }

                // Open the selected file and set it as the MediaElement's source
                IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);

                Scenario2MediaElement.SetSource(stream, file.ContentType);
            }
        }