public async Task CreateFromUri_Options() { // Setup options PropertySet to configure FFmpeg PropertySet options = new PropertySet(); options.Add("rtsp_flags", "prefer_tcp"); options.Add("stimeout", 100000); Assert.IsNotNull(options); // CreateFromUriAsync should return valid FFmpegInteropMSS object which generates valid MediaStreamSource object FFmpegInteropMSS FFmpegMSS = await FFmpegInteropMSS.CreateFromUriAsync(Constants.StreamingUriSource, new FFmpegInteropConfig { FFmpegOptions = options }); Assert.IsNotNull(FFmpegMSS); // Validate the metadata Assert.AreEqual(FFmpegMSS.AudioStreams[0].CodecName.ToLowerInvariant(), "aac"); Assert.AreEqual(FFmpegMSS.VideoStreams[0].CodecName.ToLowerInvariant(), "h264"); MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource(); Assert.IsNotNull(mss); // Based on the provided media, check if the following properties are set correctly Assert.AreEqual(true, mss.CanSeek); Assert.AreEqual(0, mss.BufferTime.TotalMilliseconds); Assert.AreEqual(Constants.StreamingUriLength, mss.Duration.TotalMilliseconds); }
public async Task CreateFromStream_Force_Audio() { Uri uri = new Uri("http://go.microsoft.com/fwlink/p/?LinkID=272585"); Assert.IsNotNull(uri); StorageFile file = await StorageFile.CreateStreamedFileFromUriAsync("d8c317bd-9fbb-4c5f-94ed-501f09841917.mp4", uri, null); Assert.IsNotNull(file); IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read); Assert.IsNotNull(readStream); // CreateFFmpegInteropMSSFromStream should return valid FFmpegInteropMSS object which generates valid MediaStreamSource object FFmpegInteropMSS FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromStream(readStream, true, false); Assert.IsNotNull(FFmpegMSS); MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource(); Assert.IsNotNull(mss); // Based on the provided media, check if the following properties are set correctly Assert.AreEqual(true, mss.CanSeek); Assert.AreNotEqual(0, mss.BufferTime.TotalMilliseconds); Assert.AreEqual(113750, mss.Duration.TotalMilliseconds); }
private async Task SetPlayer(string url) { try { PlayerLoading.Visibility = Visibility.Visible; PlayerLoadText.Text = "加载中"; if (mediaPlayer != null) { mediaPlayer.Pause(); mediaPlayer.Source = null; } if (interopMSS != null) { interopMSS.Dispose(); interopMSS = null; } interopMSS = await FFmpegInteropMSS.CreateFromUriAsync(url, _config); mediaPlayer.AutoPlay = true; mediaPlayer.Source = interopMSS.CreateMediaPlaybackItem(); player.SetMediaPlayer(mediaPlayer); } catch (Exception ex) { Utils.ShowMessageToast("播放失败" + ex.Message); } }
// Handle the returned files from file picker public async void ContinueFileOpenPicker(Windows.ApplicationModel.Activation.FileOpenPickerContinuationEventArgs args) { if (args.Files.Count > 0) { mediaElement.Stop(); try { // Open StorageFile as IRandomAccessStream to be passed to FFmpegInteropMSS StorageFile file = args.Files.FirstOrDefault(); IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read); // Instantiate FFmpeg object and pass the stream from opened file FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromStream(readStream, forceDecodeAudio, forceDecodeVideo); MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource(); if (mss != null) { // Pass MediaStreamSource to Media Element mediaElement.SetMediaStreamSource(mss); } else { DisplayErrorMessage("Cannot open media"); } } catch (Exception ex) { DisplayErrorMessage(ex.Message); } } }
public async Task GetThumbnailFromMedia() { // Create a stream from the resource URI that we have var uri = new Uri("ms-appx:///silence with album art.mp3"); var file = await StorageFile.GetFileFromApplicationUriAsync(uri); var stream = await file.OpenAsync(FileAccessMode.Read); // CreateFFmpegInteropMSSFromUri should return null if uri is blank with default parameter FFmpegInteropMSS FFmpegMSS = await FFmpegInteropMSS.CreateFromStreamAsync(stream); Assert.IsNotNull(FFmpegMSS); var thumbnailData = FFmpegMSS.ExtractThumbnail(); Assert.IsNotNull(thumbnailData); // Verify that we have a valid bitmap using (IRandomAccessStream thumbnailstream = thumbnailData.Buffer.AsStream().AsRandomAccessStream()) { BitmapDecoder decoder = await BitmapDecoder.CreateAsync(thumbnailstream); var bitmap = await decoder.GetFrameAsync(0); Assert.IsNotNull(bitmap); } }
public async Task CreateFromStream_Bad_Input() { Uri uri = new Uri("ms-appx:///test.txt"); Assert.IsNotNull(uri); StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri); Assert.IsNotNull(file); IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read); Assert.IsNotNull(readStream); // CreateFromStreamAsync should throw since test.txt is not a valid media file try { await FFmpegInteropMSS.CreateFromStreamAsync(readStream); Assert.Fail("Expected exception"); } catch (Exception) { } }
public void CreateFromUri_Bad_Input() { // CreateFFmpegInteropMSSFromUri should return null when given bad uri FFmpegInteropMSS FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri("http://This.is.a.bad.uri", false, false); Assert.IsNull(FFmpegMSS); }
private void button2_Click(object sender, RoutedEventArgs e) { m_FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromStream(m_mediaStream, false, false); MediaStreamSource mss = m_FFmpegMSS.GetMediaStreamSource(); mediaElement1.SetMediaStreamSource(mss); }
private void OpenUri(String uri) { OpenMedia((mss, config) => { FFmpegInteropMSS.CreateFromUri(uri, mss, config); }); }
public void StopPlay() { HohoemaApp.MediaPlayer.Pause(); HohoemaApp.MediaPlayer.Source = null; _VideoMSS?.Dispose(); _VideoMSS = null; _MediaSource?.Dispose(); _MediaSource = null; foreach (var div in GetAllQuality()) { if (div.NowPlaying) { div.OnPlayDone(); } } Debug.WriteLine("stream dispose"); NicoVideoCachedStream?.Dispose(); NicoVideoCachedStream = null; var smtc = HohoemaApp.MediaPlayer.SystemMediaTransportControls; smtc.DisplayUpdater.ClearAll(); smtc.IsEnabled = false; smtc.DisplayUpdater.Update(); Db.VideoPlayHistoryDb.VideoPlayed(this.RawVideoId); OnPropertyChanged(nameof(IsPlayed)); }
private async Task <FFmpegInteropMSS> CreateMediaSourceAndPlayer(MediaPlayerElement playerElement, FFmpegInteropMSS ffmpegMss, Clip clip) { if (ffmpegMss != null) { ffmpegMss.Dispose(); } FFmpegInteropConfig conf = new FFmpegInteropConfig(); conf.StreamBufferSize = BufferSizeInBytes; MediaPlayer player = playerElement.MediaPlayer; if (player == null) { player = CreatePlayer(); } using (var stream = await clip.ClipFile.OpenAsync(Windows.Storage.FileAccessMode.Read)) { ffmpegMss = await FFmpegInteropMSS.CreateFromStreamAsync(stream, conf); } player.Source = ffmpegMss.CreateMediaPlaybackItem(); playerElement.SetMediaPlayer(player); return(ffmpegMss); }
public async Task CreateFromStream_Options() { Uri uri = new Uri(_UriSource); Assert.IsNotNull(uri); StorageFile file = await StorageFile.CreateStreamedFileFromUriAsync("d8c317bd-9fbb-4c5f-94ed-501f09841917.mp4", uri, null); Assert.IsNotNull(file); IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read); Assert.IsNotNull(readStream); // Setup options PropertySet to configure FFmpeg PropertySet options = new PropertySet(); options.Add("rtsp_flags", "prefer_tcp"); options.Add("stimeout", 100000); Assert.IsNotNull(options); // CreateFFmpegInteropMSSFromStream should return valid FFmpegInteropMSS object which generates valid MediaStreamSource object FFmpegInteropMSS FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromStream(readStream, false, false, options); Assert.IsNotNull(FFmpegMSS); MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource(); Assert.IsNotNull(mss); // Based on the provided media, check if the following properties are set correctly Assert.AreEqual(true, mss.CanSeek); Assert.AreNotEqual(0, mss.BufferTime.TotalMilliseconds); Assert.AreEqual(_UriLength, mss.Duration.TotalMilliseconds); }
public async Task CreateFromStream_Default() { Uri uri = new Uri(Constants.DownloadUriSource); Assert.IsNotNull(uri); StorageFile file = await StorageFile.CreateStreamedFileFromUriAsync(Constants.DownloadStreamedFileName, uri, null); Assert.IsNotNull(file); IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read); Assert.IsNotNull(readStream); // CreateFromStreamAsync should return valid FFmpegInteropMSS object which generates valid MediaStreamSource object FFmpegInteropMSS FFmpegMSS = await FFmpegInteropMSS.CreateFromStreamAsync(readStream); Assert.IsNotNull(FFmpegMSS); MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource(); Assert.IsNotNull(mss); // Based on the provided media, check if the following properties are set correctly Assert.AreEqual(true, mss.CanSeek); Assert.AreEqual(0, mss.BufferTime.TotalMilliseconds); Assert.AreEqual(Constants.DownloadUriLength, mss.Duration.TotalMilliseconds); }
private async void TryToUseFFmpegURI() { try { // Set FFmpeg specific options. List of options can be found in https://www.ffmpeg.org/ffmpeg-protocols.html // Below are some sample options that you can set to configure RTSP streaming // Config.FFmpegOptions.Add("rtsp_flags", "prefer_tcp"); // Config.FFmpegOptions.Add("stimeout", 100000); // Instantiate FFmpegInteropMSS using the URI VideoBox.Stop(); ffmpegMss = await FFmpegInteropMSS.CreateFromUriAsync(inputURI); var source = ffmpegMss.CreateMediaPlaybackItem(); // Pass MediaStreamSource to Media Element VideoBox.SetPlaybackSource(source); } catch (Exception ex) { ShowDialog.DisplayErrorMessage(ex.Message); } //try //{ // // Set FFmpeg specific options. List of options can be found in https://www.ffmpeg.org/ffmpeg-protocols.html // PropertySet options = new PropertySet(); // // Below are some sample options that you can set to configure RTSP streaming // // options.Add("rtsp_flags", "prefer_tcp"); // // options.Add("stimeout", 100000); // // Instantiate FFmpegInteropMSS using the URI // ffmpegMss = await FFmpegInteropMSS.CreateFromUriAsync(inputURI); // if (ffmpegMss != null) // { // MediaStreamSource mss = ffmpegMss.GetMediaStreamSource(); // if (mss != null) // { // // Pass MediaStreamSource to Media Element // VideoBox.Source = MediaSource.CreateFromMediaStreamSource(mss); // } // else // { // ShowDialog.DisplayErrorMessage(ErrorInfo.CannotOpen); // } // } // else // { // ShowDialog.DisplayErrorMessage(ErrorInfo.CannotOpen); // } //} //catch (Exception ex) //{ // ShowDialog.DisplayErrorMessage(ex.Message); //} }
private async Task OpenLocalFile(StorageFile file) { currentFile = file; mediaPlayer.Source = null; // Open StorageFile as IRandomAccessStream to be passed to FFmpegInteropMSS IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read); try { StorageApplicationPermissions.FutureAccessList.Clear(); StorageApplicationPermissions.FutureAccessList.Add(file); // Instantiate FFmpegInteropMSS using the opened local file stream FFmpegMSS = await FFmpegInteropMSS.CreateFromStreamAsync(readStream, Config); var tags = FFmpegMSS.MetadataTags.ToArray(); if (AutoCreatePlaybackItem) { CreatePlaybackItemAndStartPlaybackInternal(); } else { playbackItem = null; } } catch (Exception ex) { await DisplayErrorMessage(ex.Message); } }
private async void Play(Grid parent, GalleryContent item, File file) { try { if (!file.Local.IsDownloadingCompleted && !SettingsService.Current.IsStreamingEnabled) { return; } if (_surface != null && _mediaPlayerElement != null) { _surface.Children.Remove(_mediaPlayerElement); _surface = null; } if (_mediaPlayer == null) { _mediaPlayer = Task.Run(() => new MediaPlayer()).Result; _mediaPlayer.VolumeChanged += OnVolumeChanged; _mediaPlayer.SourceChanged += OnSourceChanged; _mediaPlayer.MediaOpened += OnMediaOpened; _mediaPlayer.PlaybackSession.PlaybackStateChanged += OnPlaybackStateChanged; _mediaPlayerElement.SetMediaPlayer(_mediaPlayer); } var dpi = DisplayInformation.GetForCurrentView().LogicalDpi / 96.0f; _mediaPlayer.SetSurfaceSize(new Size(parent.ActualWidth * dpi, parent.ActualHeight * dpi)); _surface = parent; _surface.Children.Add(_mediaPlayerElement); if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.MediaTransportControls", "ShowAndHideAutomatically")) { Transport.ShowAndHideAutomatically = true; } Transport.DownloadMaximum = file.Size; Transport.DownloadValue = file.Local.DownloadOffset + file.Local.DownloadedPrefixSize; var streamable = SettingsService.Current.IsStreamingEnabled && item.IsStreamable && !file.Local.IsDownloadingCompleted; if (streamable) { _streamingInterop = new FFmpegInteropMSS(new FFmpegInteropConfig()); var interop = await _streamingInterop.CreateFromFileAsync(ViewModel.ProtoService.Client, file); _mediaPlayer.Source = interop.CreateMediaPlaybackItem(); Transport.DownloadMaximum = file.Size; Transport.DownloadValue = file.Local.DownloadOffset + file.Local.DownloadedPrefixSize; } else { _mediaPlayer.Source = MediaSource.CreateFromUri(new Uri("file:///" + file.Local.Path)); } _mediaPlayer.IsLoopingEnabled = item.IsLoop; _mediaPlayer.Play(); } catch { } }
private async void LoadClip(Clip clip) { switch (clip.Camera) { case Camera.LeftRepeater: _leftFfmpegInterop = await CreateMediaSourceAndPlayer(LeftPlayer.VideoPlayerElement, _leftFfmpegInterop, clip); break; case Camera.Front: _frontFfmpegInterop = await CreateMediaSourceAndPlayer(FrontPlayer.VideoPlayerElement, _frontFfmpegInterop, clip); break; case Camera.RightRepeater: _rightFfmpegInterop = await CreateMediaSourceAndPlayer(RightPlayer.VideoPlayerElement, _rightFfmpegInterop, clip); break; case Camera.Back: _backFfmpegInterop = await CreateMediaSourceAndPlayer(BackPlayer.VideoPlayerElement, _backFfmpegInterop, clip); break; default: throw new InvalidOperationException(); } _mediaTimelineController.Position = TimeSpan.Zero; }
public async Task StartPlayback(MediaPlayer player) { string contentType = string.Empty; var stream = await StreamRef.OpenReadAsync(); if (!stream.ContentType.EndsWith("mp4")) { _VideoMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromStream(stream, false, false); var mss = _VideoMSS.GetMediaStreamSource(); mss.SetBufferedRange(TimeSpan.Zero, TimeSpan.Zero); _MediaSource = MediaSource.CreateFromMediaStreamSource(mss); } else { _MediaSource = MediaSource.CreateFromStream(stream, stream.ContentType); } if (_MediaSource != null) { player.Source = _MediaSource; _Stream = stream; _PlayingMediaPlayer = player; } else { throw new NotSupportedException("can not play video. vide source from download progress stream."); } }
public void CreateFromUri_Destructor() { // CreateFFmpegInteropMSSFromUri should return valid FFmpegInteropMSS object which generates valid MediaStreamSource object FFmpegInteropMSS FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(_UriSource, false, false); Assert.IsNotNull(FFmpegMSS); MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource(); Assert.IsNotNull(mss); // Based on the provided media, check if the following properties are set correctly Assert.AreEqual(true, mss.CanSeek); Assert.AreNotEqual(0, mss.BufferTime.TotalMilliseconds); Assert.AreEqual(_UriLength, mss.Duration.TotalMilliseconds); // Keep original reference and ensure object are not destroyed until each reference is released by setting it to nullptr FFmpegInteropMSS OriginalFFmpegMSS = FFmpegMSS; MediaStreamSource Originalmss = mss; FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri("", false, false); Assert.IsNull(FFmpegMSS); Assert.IsNotNull(OriginalFFmpegMSS); Assert.IsNotNull(Originalmss); mss = null; Assert.IsNull(mss); Assert.IsNotNull(Originalmss); OriginalFFmpegMSS = null; Originalmss = null; Assert.IsNull(OriginalFFmpegMSS); Assert.IsNull(Originalmss); }
protected override async Task <MediaSource> GetPlyaingVideoMediaSource() { var file = await StorageFile.GetFileFromPathAsync(File.Path); var stream = await file.OpenReadAsync(); var contentType = stream.ContentType; if (contentType == null) { throw new NotSupportedException("can not play video file. " + File.Path); } if (contentType == "video/mp4") { return(MediaSource.CreateFromStream(stream, contentType)); } else { _VideoMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromStream(stream, false, false); var mss = _VideoMSS.GetMediaStreamSource(); mss.SetBufferedRange(TimeSpan.Zero, TimeSpan.Zero); return(MediaSource.CreateFromMediaStreamSource(mss)); } }
public void Stream(Object source, EventArgs e) { try { PropertySet options = new PropertySet(); Player.Stop(); options.Add("rtsp_transport", "tcp"); FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(Settings.Source, false, true, options); if (FFmpegMSS != null) { MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource(); if (mss != null) { Player.SetMediaStreamSource(mss); } else { Errors(1); return; } } else { Errors(2); return; } } catch { Errors(3); return; } }
private void URIBoxKeyUp(object sender, KeyRoutedEventArgs e) { var textBox = sender as TextBox; String uri = textBox.Text; // Only respond when the text box is not empty and after Enter key is pressed if (e.Key == Windows.System.VirtualKey.Enter && !String.IsNullOrWhiteSpace(uri)) { // Mark event as handled to prevent duplicate event to re-triggered e.Handled = true; try { // Read toggle switches states and use them to setup FFmpeg MSS bool forceDecodeAudio = toggleSwitchAudioDecode.IsOn; bool forceDecodeVideo = toggleSwitchVideoDecode.IsOn; // Set FFmpeg specific options. List of options can be found in https://www.ffmpeg.org/ffmpeg-protocols.html PropertySet options = new PropertySet(); // Below are some sample options that you can set to configure RTSP streaming // options.Add("rtsp_flags", "prefer_tcp"); // options.Add("stimeout", 100000); // Instantiate FFmpegInteropMSS using the URI mediaElement.Stop(); FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(uri, forceDecodeAudio, forceDecodeVideo, options); if (FFmpegMSS != null) { MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource(); if (mss != null) { // Pass MediaStreamSource to Media Element mediaElement.SetMediaStreamSource(mss); // Close control panel after opening media Splitter.IsPaneOpen = false; } else { DisplayErrorMessage("Cannot open media"); } } else { DisplayErrorMessage("Cannot open media"); } } catch (Exception ex) { DisplayErrorMessage(ex.Message); } } }
public void Dispose() { _MediaSource.Dispose(); _MediaSource = null; _VideoMSS.Dispose(); _VideoMSS = null; _Stream.Dispose(); _Stream = null; _PlayingMediaPlayer = null; }
public void CreateFromUri_Null() { // CreateFFmpegInteropMSSFromUri should return null if uri is blank with default parameter FFmpegInteropMSS FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(string.Empty, false, false); Assert.IsNull(FFmpegMSS); // CreateFFmpegInteropMSSFromUri should return null if uri is blank with non default parameter FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(string.Empty, true, true); Assert.IsNull(FFmpegMSS); }
public void CreateFromStream_Null() { // CreateFFmpegInteropMSSFromStream should return null if stream is null with default parameter FFmpegInteropMSS FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromStream(null, false, false); Assert.IsNull(FFmpegMSS); // CreateFFmpegInteropMSSFromStream should return null if stream is null with non default parameter FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromStream(null, true, true); Assert.IsNull(FFmpegMSS); }
private MediaStreamSource CreateMSSFromStream(IRandomAccessStream stream, FFmpegInteropMSSConfig config) { // Create the MSS IActivationFactory mssFactory = WindowsRuntimeMarshal.GetActivationFactory(typeof(MediaStreamSource)); MediaStreamSource mss = mssFactory.ActivateInstance() as MediaStreamSource; // Create the FFmpegInteropMSS from the provided stream FFmpegInteropMSS.CreateFromStream(stream, mss, config); return(mss); }
private async void OpenLocalFile(object sender, RoutedEventArgs e) { FileOpenPicker filePicker = new FileOpenPicker(); filePicker.ViewMode = PickerViewMode.Thumbnail; filePicker.SuggestedStartLocation = PickerLocationId.VideosLibrary; filePicker.FileTypeFilter.Add("*"); // Show file picker so user can select a file StorageFile file = await filePicker.PickSingleFileAsync(); if (file != null) { mediaElement.Stop(); // Open StorageFile as IRandomAccessStream to be passed to FFmpegInteropMSS IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read); try { // Read toggle switches states and use them to setup FFmpeg MSS bool forceDecodeAudio = toggleSwitchAudioDecode.IsOn; bool forceDecodeVideo = toggleSwitchVideoDecode.IsOn; // Instantiate FFmpegInteropMSS using the opened local file stream FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromStream(readStream, forceDecodeAudio, forceDecodeVideo); MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource(); var chapters = FFmpegMSS.GetChapterMetadata(); foreach (var chapter in chapters) { Debug.WriteLine("{0} : {1} ({2} :: {3})", chapter.GetChapter(), chapter.GetTitle(), chapter.GetStartTime(), chapter.GetEndTime()); } if (mss != null) { // Pass MediaStreamSource to Media Element mediaElement.SetMediaStreamSource(mss); // Close control panel after file open Splitter.IsPaneOpen = false; } else { DisplayErrorMessage("Cannot open media"); } } catch (Exception ex) { DisplayErrorMessage(ex.Message); } } }
private async void OpenFile(StorageFile file) { // Populate the URI box with the path of the file selected uriBox.Text = file.Path; IRandomAccessStream stream = await file.OpenReadAsync(); OpenMedia((mss, config) => { FFmpegInteropMSS.CreateFromStream(stream, mss, config); }); }
private void Dispose() { Element2.Reset(); Element0.Reset(); Element1.Reset(); if (_surface != null) { _surface.Children.Remove(_mediaPlayerElement); _surface = null; } if (_streamingInterop != null) { var interop = _streamingInterop; _streamingInterop = null; Task.Run(() => interop?.Dispose()); } if (_mediaPlayer != null) { _mediaPlayer.VolumeChanged -= OnVolumeChanged; _mediaPlayer.SourceChanged -= OnSourceChanged; _mediaPlayer.MediaOpened -= OnMediaOpened; _mediaPlayer.PlaybackSession.PlaybackStateChanged -= OnPlaybackStateChanged; _mediaPlayerElement.SetMediaPlayer(null); //_mediaPlayerElement.AreTransportControlsEnabled = false; //_mediaPlayerElement.TransportControls = null; //_mediaPlayerElement = null; if (_compactLifetime == null) { _mediaPlayer.Dispose(); _mediaPlayer = null; } OnSourceChanged(); } if (_request != null) { _request.RequestRelease(); _request = null; } if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.MediaTransportControls", "ShowAndHideAutomatically")) { Transport.ShowAndHideAutomatically = false; } }
public async Task CreateFromStream_Null() { // CreateFromStreamAsync should throw if stream is null with default parameter try { await FFmpegInteropMSS.CreateFromStreamAsync(null); Assert.Fail("Expected exception"); } catch (Exception) { } }
private async void OpenLocalFile(object sender, RoutedEventArgs e) { FileOpenPicker filePicker = new FileOpenPicker(); filePicker.ViewMode = PickerViewMode.Thumbnail; filePicker.SuggestedStartLocation = PickerLocationId.VideosLibrary; filePicker.FileTypeFilter.Add("*"); // Show file picker so user can select a file StorageFile file = await filePicker.PickSingleFileAsync(); if (file != null) { mediaElement.Stop(); // Open StorageFile as IRandomAccessStream to be passed to FFmpegInteropMSS IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read); try { // Read toggle switches states and use them to setup FFmpeg MSS bool forceDecodeAudio = toggleSwitchAudioDecode.IsOn; bool forceDecodeVideo = toggleSwitchVideoDecode.IsOn; // Instantiate FFmpegInteropMSS using the opened local file stream FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromStream(readStream, forceDecodeAudio, forceDecodeVideo); MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource(); if (mss != null) { // Pass MediaStreamSource to Media Element mediaElement.SetMediaStreamSource(mss); // Close control panel after file open Splitter.IsPaneOpen = false; } else { DisplayErrorMessage("Cannot open media"); } } catch (Exception ex) { DisplayErrorMessage(ex.Message); } } }
private async void AppBarButton_Browse_Click(object sender, RoutedEventArgs e) { FileOpenPicker filePicker = new FileOpenPicker(); filePicker.ViewMode = PickerViewMode.Thumbnail; filePicker.SuggestedStartLocation = PickerLocationId.VideosLibrary; filePicker.FileTypeFilter.Add("*"); // Show file picker so user can select a file StorageFile file = await filePicker.PickSingleFileAsync(); if (file != null) { mediaElement.Stop(); // Open StorageFile as IRandomAccessStream to be passed to FFmpegInteropMSS IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read); try { // Instantiate FFmpeg object and pass the stream from opened file FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromStream(readStream, forceDecodeAudio, forceDecodeVideo); MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource(); if (mss != null) { // Pass MediaStreamSource to Media Element mediaElement.SetMediaStreamSource(mss); } else { DisplayErrorMessage("Cannot open media"); } } catch (Exception ex) { DisplayErrorMessage(ex.Message); } } // Set the TopAppBar to non-sticky so it will hide automatically after first file open this.TopAppBar.IsSticky = false; this.TopAppBar.IsOpen = false; }
private void URIBoxKeyUp(object sender, KeyRoutedEventArgs e) { var textBox = sender as TextBox; String uri = textBox.Text; // Only respond when the text box is not empty and after Enter key is pressed if (e.Key == Windows.System.VirtualKey.Enter && !String.IsNullOrWhiteSpace(uri)) { // Mark event as handled to prevent duplicate event to re-triggered e.Handled = true; try { // Read toggle switches states and use them to setup FFmpeg MSS bool forceDecodeAudio = toggleSwitchAudioDecode.IsOn; bool forceDecodeVideo = toggleSwitchVideoDecode.IsOn; // Instantiate FFmpegInteropMSS using the URI mediaElement.Stop(); FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(uri, forceDecodeAudio, forceDecodeVideo); if (FFmpegMSS != null) { MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource(); if (mss != null) { // Pass MediaStreamSource to Media Element mediaElement.SetMediaStreamSource(mss); // Close control panel after opening media Splitter.IsPaneOpen = false; } else { DisplayErrorMessage("Cannot open media"); } } else { DisplayErrorMessage("Cannot open media"); } } catch (Exception ex) { DisplayErrorMessage(ex.Message); } } }