/// <summary> /// Handles the MediaOpened event of the CurrentMediaElement control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void MediaElement_MediaOpened(object sender, RoutedEventArgs e) { TimeCode currentDuration = TimeCode.FromSeconds(this.Player.MediaElement.Duration.TotalSeconds, this.VideoAsset.FrameRate); this.VideoAsset.Duration = currentDuration; SmoothStreamingVideoAsset smoothStreamingVideoAsset = this.Asset as SmoothStreamingVideoAsset; if (smoothStreamingVideoAsset != null && smoothStreamingVideoAsset.StartPosition != this.Player.MediaElement.StartPosition.TotalSeconds) { smoothStreamingVideoAsset.StartPosition = this.Player.MediaElement.StartPosition.TotalSeconds; } }
public void ShouldRetrieveEmptyAssetCacheIfThereAreNoFragmentsCached() { SmoothStreamingVideoAsset asset = new SmoothStreamingVideoAsset { Duration = TimeCode.FromSeconds(60d, SmpteFrameRate.Smpte24), Source = new Uri("http://test/video.ism/manifest") }; ICacheManager cacheManager = this.CreateCacheManager(); IDictionary <double, double> assetCache = cacheManager.RetrieveAssetCache(asset); Assert.AreEqual(0, assetCache.Count); }
private void PopulateAudioStreams() { this.AvailableAudioStreams.Clear(); SmoothStreamingVideoAsset smoothStreamingVideoAsset = this.Asset as SmoothStreamingVideoAsset; if (smoothStreamingVideoAsset != null && smoothStreamingVideoAsset.AudioStreams != null) { if (smoothStreamingVideoAsset.AudioStreams.Count == 0 || (smoothStreamingVideoAsset.AudioStreams.Count == 1 && string.IsNullOrEmpty(smoothStreamingVideoAsset.AudioStreams[0].Name))) { this.AvailableAudioStreams.Add( new StreamOption { Name = "Default", PreviewSelected = false, SequenceSelected = false }); } else { foreach (var audioStream in smoothStreamingVideoAsset.AudioStreams) { this.AvailableAudioStreams.Add( new StreamOption { Name = audioStream.Name, PreviewSelected = false, SequenceSelected = false }); } var firstAudioStream = this.AvailableAudioStreams[0]; var audio = smoothStreamingVideoAsset.AudioStreams.First(a => a.Name == firstAudioStream.Name); this.VideoAssetInOut.PreviewAudioStream = audio; this.VideoAssetInOut.SequenceAudioStreams.Add(audio); } } else { this.AvailableAudioStreams.Add( new StreamOption { Name = "Default", PreviewSelected = false, SequenceSelected = false }); } var firstAudio = this.AvailableAudioStreams[0]; firstAudio.PreviewSelected = true; firstAudio.SequenceSelected = true; }
private void PopulateVideoStreams() { this.AvailableVideoStreams.Clear(); SmoothStreamingVideoAsset smoothStreamingVideoAsset = this.Asset as SmoothStreamingVideoAsset; if (smoothStreamingVideoAsset != null && smoothStreamingVideoAsset.VideoStreams != null) { if (smoothStreamingVideoAsset.VideoStreams.Count == 0 || (smoothStreamingVideoAsset.VideoStreams.Count == 1 && string.IsNullOrEmpty(smoothStreamingVideoAsset.VideoStreams[0]))) { this.AvailableVideoStreams.Add( new StreamOption { Name = "Default", PreviewSelected = false, SequenceSelected = false }); } else { foreach (var videoStream in smoothStreamingVideoAsset.VideoStreams) { this.AvailableVideoStreams.Add( new StreamOption { Name = videoStream, PreviewSelected = false, SequenceSelected = false }); } var firstVideoStream = this.AvailableVideoStreams[0]; this.VideoAssetInOut.PreviewVideoCamera = firstVideoStream.Name; this.VideoAssetInOut.SequenceVideoCamera = firstVideoStream.Name; } } else { this.AvailableVideoStreams.Add( new StreamOption { Name = "Default", PreviewSelected = false, SequenceSelected = false }); } var firstVideoCamera = this.AvailableVideoStreams[0]; firstVideoCamera.PreviewSelected = true; firstVideoCamera.SequenceSelected = true; }
/// <summary> /// Sets the source of the player. /// </summary> /// <param name="asset">The asset representing the source.</param> public void SetSource(Asset asset) { if (asset.IsAdaptiveAsset) { SmoothStreamingVideoAsset videoAsset = asset as SmoothStreamingVideoAsset; if (videoAsset != null) { this.externalManifestFiles = videoAsset.ExternalManifests; videoAsset.DataStreams.ForEach(this.InStreamData.LogStreams.Add); } this.MediaPlugin.AdaptiveSource = asset.Source; } else { this.MediaPlugin.Source = asset.Source; } }
/// <summary> /// Sets the source of the player. /// </summary> /// <param name="asset">The asset representing the source.</param> public void SetSource(Asset asset) { if (asset.IsAdaptiveAsset) { SmoothStreamingVideoAsset videoAsset = asset as SmoothStreamingVideoAsset; if (videoAsset != null) { this.externalManifestFiles = videoAsset.ExternalManifests; this.InStreamData.DataStreams.AddRange(videoAsset.DataStreams); } this.codecPrivateDataParser.GetFrameRateAsync(asset.Source); this.MediaElement.SmoothStreamingSource = asset.Source; } else { this.MediaElement.Source = asset.Source; } }
/// <summary> /// Handles the MediaOpened event of the MediaElement control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void MediaElement_MediaOpened(object sender, RoutedEventArgs e) { // HACK: For non-smooth streaming content. // this.Position = TimeSpan.FromSeconds(this.timelineElement.InPosition.TotalSeconds); // this.Position = TimeSpan.FromSeconds(0); this.In = TimeSpan.FromSeconds(this.timelineElement.InPosition.TotalSeconds); VideoAsset videoAsset = this.timelineElement.Asset as VideoAsset; AudioAsset audioAsset = this.timelineElement.Asset as AudioAsset; if (videoAsset != null) { if (TimeSpan.FromSeconds(videoAsset.Duration.TotalSeconds).TotalSeconds != this.mediaElement.Duration.TotalSeconds) { videoAsset.Duration = TimeCode.FromSeconds(this.mediaElement.Duration.TotalSeconds, videoAsset.FrameRate); this.Duration = TimeSpan.FromSeconds(videoAsset.Duration.TotalSeconds + this.timelineElement.InPosition.TotalSeconds); } } if (audioAsset != null) { if (audioAsset.Duration != this.mediaElement.Duration.TotalSeconds) { audioAsset.Duration = this.mediaElement.Duration.TotalSeconds; this.Duration = TimeSpan.FromSeconds(audioAsset.Duration + this.timelineElement.InPosition.TotalSeconds); } } SmoothStreamingVideoAsset smoothStreamingVideoAsset = this.timelineElement.Asset as SmoothStreamingVideoAsset; if (smoothStreamingVideoAsset != null && smoothStreamingVideoAsset.StartPosition != this.mediaElement.StartPosition.TotalSeconds) { smoothStreamingVideoAsset.StartPosition = this.mediaElement.StartPosition.TotalSeconds; } // if (this.mediaElement.StartPosition.TotalSeconds > this.timelineElement.InPosition.TotalSeconds) // { // this.timelineElement.InPosition = TimeCode.FromSeconds(this.mediaElement.StartPosition.TotalSeconds, this.timelineElement.InPosition.FrameRate); // this.timelineElement.OutPosition += TimeCode.FromSeconds(this.mediaElement.StartPosition.TotalSeconds, this.timelineElement.InPosition.FrameRate); // } }
private void HandleAudioSequenceSelectionChanged(StreamOption audioStream) { if (this.availableAudioStreams.Count(s => s.SequenceSelected) > maxNumberOfAudioTracks + 1) { audioStream.SequenceSelected = false; return; } SmoothStreamingVideoAsset smoothStreamingVideoAsset = this.Asset as SmoothStreamingVideoAsset; if (smoothStreamingVideoAsset != null) { var audio = smoothStreamingVideoAsset.AudioStreams.First(a => a.Name == audioStream.Name); if (audioStream.SequenceSelected) { this.VideoAssetInOut.SequenceAudioStreams.Add(audio); } else { this.VideoAssetInOut.SequenceAudioStreams.Remove(audio); } } }
public void ShouldAddMultipleAudioStreamsToSequenceAudioStreamsWhenExecutingAudioSequenceSelectionChangedCommandWithDifferentAudios() { var viewModel = this.CreateViewModel(); SmoothStreamingVideoAsset smoothStreamingVideoAsset = new SmoothStreamingVideoAsset(); VideoAssetInOut videoInOut = new VideoAssetInOut(smoothStreamingVideoAsset); viewModel.VideoAssetInOut = videoInOut; var audioStreamEs = new AudioStream("audio_es", false); var audioStreamEn = new AudioStream("audio_en", false); var audioStreamDirector = new AudioStream("audio_director", false); smoothStreamingVideoAsset.AudioStreams.Add(audioStreamEs); smoothStreamingVideoAsset.AudioStreams.Add(audioStreamEn); smoothStreamingVideoAsset.AudioStreams.Add(audioStreamDirector); viewModel.Asset = smoothStreamingVideoAsset; Assert.AreEqual(1, viewModel.VideoAssetInOut.SequenceAudioStreams.Count); viewModel.AudioSequenceSelectionChangedCommand.Execute( new StreamOption { Name = "audio_en", SequenceSelected = true }); Assert.AreEqual(2, viewModel.VideoAssetInOut.SequenceAudioStreams.Count); Assert.AreSame(audioStreamEn, viewModel.VideoAssetInOut.SequenceAudioStreams[1]); viewModel.AudioSequenceSelectionChangedCommand.Execute(new StreamOption { Name = "audio_director", SequenceSelected = true }); Assert.AreEqual(3, viewModel.VideoAssetInOut.SequenceAudioStreams.Count); Assert.AreSame(audioStreamDirector, viewModel.VideoAssetInOut.SequenceAudioStreams[2]); }
public void ShouldChangeSequenceVideoWhenExecutingVideoSequenceSelectionChangedCommand() { var viewModel = this.CreateViewModel(); SmoothStreamingVideoAsset smoothStreamingVideoAsset = new SmoothStreamingVideoAsset(); VideoAssetInOut videoInOut = new VideoAssetInOut(smoothStreamingVideoAsset); viewModel.VideoAssetInOut = videoInOut; smoothStreamingVideoAsset.VideoStreams.Add("camera1"); smoothStreamingVideoAsset.VideoStreams.Add("camera2"); viewModel.Asset = smoothStreamingVideoAsset; Assert.AreEqual("camera1", viewModel.VideoAssetInOut.SequenceVideoCamera); viewModel.VideoSequenceSelectionChangedCommand.Execute(new StreamOption { Name = "camera2" }); Assert.IsNotNull(viewModel.VideoAssetInOut.SequenceVideoCamera); Assert.AreEqual("camera2", viewModel.VideoAssetInOut.SequenceVideoCamera); }
public void ShouldUpdateAssetCacheWithNewOffsetsWhenCacheIsUpdated() { SmoothStreamingVideoAsset asset = new SmoothStreamingVideoAsset { Duration = TimeCode.FromSeconds(8d, SmpteFrameRate.Smpte24), Source = new Uri("http://test/video.ism/manifest") }; this.cache.CacheItems.Add(@"http://test/video.ism/QualityLevels(400000)/Fragments(video=0)", new CacheItem()); this.cache.CacheItems.Add(@"http://test/video.ism/QualityLevels(400000)/Fragments(video=60000000)", new CacheItem()); this.cache.CacheItems.Add(@"http://test/video.ism/QualityLevels(400000)/Fragments(video=80000000)", new CacheItem()); ICacheManager cacheManager = this.CreateCacheManager(); IDictionary <double, double> assetCache = cacheManager.RetrieveAssetCache(asset); Assert.AreEqual(3, assetCache.Count); this.cache.InvokeCacheUpdated("http://test/video.ism/QualityLevels(400000)/Fragments(video=40000000)"); assetCache = cacheManager.RetrieveAssetCache(asset); Assert.AreEqual(4, assetCache.Count); Assert.AreEqual(0, assetCache.Keys.ElementAt(0)); Assert.AreEqual(0, assetCache.Values.ElementAt(0)); Assert.AreEqual(0.75, assetCache.Keys.ElementAt(1)); Assert.AreEqual(0.75, assetCache.Values.ElementAt(1)); Assert.AreEqual(1, assetCache.Keys.ElementAt(2)); Assert.AreEqual(0.75, assetCache.Values.ElementAt(2)); Assert.AreEqual(0.50, assetCache.Keys.ElementAt(3)); Assert.AreEqual(0.50, assetCache.Values.ElementAt(3)); }
private static VideoAsset CreateVideoAsset( string azureId, bool isAdaptiveStreaming, IList <string> dataStreams, Uri sourceUri, string title, Uri thumbnailUri, double?duration, SmpteFrameRate smpteFrameRate, double width, double height, IList <AudioStreamInfo> audioStreamsInformation, IList <string> videoStreamInformation, string archiveUrl, string cmsId, string vodUrl) { VideoAsset videoAsset; if (isAdaptiveStreaming) { SmoothStreamingVideoAsset tempAsset = new SmoothStreamingVideoAsset(); if (dataStreams != null && dataStreams.Count > 0) { tempAsset.DataStreams = (List <string>)dataStreams; } if (audioStreamsInformation != null && audioStreamsInformation.Count > 0) { audioStreamsInformation.ForEach(info => tempAsset.AudioStreams.Add(new AudioStream(info.Name, info.IsStereo))); } if (videoStreamInformation != null && videoStreamInformation.Count > 0) { tempAsset.VideoStreams = (List <string>)videoStreamInformation; } tempAsset.VodUri = string.IsNullOrEmpty(vodUrl) ? null : new Uri(vodUrl); videoAsset = tempAsset; } else { videoAsset = new VideoAsset(); } videoAsset.ProviderUri = CreateUri("Videos"); videoAsset.Created = DateTime.Now; videoAsset.Title = title; videoAsset.ThumbnailSource = (thumbnailUri != null) ? thumbnailUri.ToString() : null; videoAsset.Duration = TimeCode.FromSeconds(duration.HasValue ? duration.Value : 0, smpteFrameRate); videoAsset.FrameRate = smpteFrameRate; videoAsset.Width = (int)width; videoAsset.Height = (int)height; videoAsset.ArchiveURL = archiveUrl; videoAsset.CMSId = cmsId; videoAsset.AzureId = azureId; videoAsset.Source = sourceUri; videoAsset.ResourceType = ResourceType.SmoothStream; return(videoAsset); }