public void ShouldNotChangeCurrentFolderIfParentFolderIsNullAndUpArrowCommandIsExecuted() { VideoAsset videoAsset = new VideoAsset { Title = "VideoAsset" }; FolderAsset folderAsset = new FolderAsset { Title = "ParentFolder", }; folderAsset.AddAssets(new ObservableCollection <Asset> { videoAsset }); var presentationModel = this.CreatePresentationModel(); presentationModel.Assets = new List <Asset> { folderAsset }; Assert.AreEqual(1, presentationModel.Assets.Count); presentationModel.UpArrowCommand.Execute(null); Assert.AreEqual(1, presentationModel.Assets.Count); }
public void UpdateDisplay() { // display name AssetName.Text = Asset.Name; // load image/video ImgAsset.Source = null; VideoAsset.Source = null; if (Asset.Type == AssetType.Image) { ImgAsset.Source = new BitmapImage(new Uri(Asset.CurrentPath)); lbhymn.Visibility = Visibility.Visible; lbliturgy.Visibility = Visibility.Visible; lbbells.Visibility = Visibility.Hidden; } if (Asset.Type == AssetType.Video) { VideoAsset.Source = new Uri(Asset.CurrentPath); VideoAsset.MediaEnded += VideoAsset_MediaEnded; VideoAsset.Volume = 0; VideoAsset.Play(); lbhymn.Visibility = Visibility.Hidden; lbliturgy.Visibility = Visibility.Hidden; lbbells.Visibility = Visibility.Hidden; } if (Asset.Type == AssetType.Audio) { ImgAsset.Source = new BitmapImage(new Uri("pack://application:,,,/ViewControls/Images/musicnote.png")); lbhymn.Visibility = Visibility.Hidden; lbliturgy.Visibility = Visibility.Hidden; lbinsert.Visibility = Visibility.Hidden; lbbells.Visibility = Visibility.Visible; } }
public void ShouldReadMetadataAndPopulateAssetMetadataDetails() { this.regionManager.Regions.Add(new MockRegion { Name = RegionNames.ClipMetadataRegion }); this.configurationService.GetParameterValueReturnFunction = parameter => { if (parameter == "MetadataFields") { return("Title;Duration;FrameRate"); } return(null); }; var presentationModel = this.CreateMetadataViewPresentationModel(); Asset asset = new VideoAsset { Title = "Test Video" }; Assert.IsNull(presentationModel.AssetMetadataDetails); var payload = new TimelineElement { Asset = asset }; this.showMetadataEvent.SubscribeArgumentAction(payload); Assert.AreEqual(3, presentationModel.AssetMetadataDetails.Count); }
public void ShouldShowAssetsOfParentFolderWhenUpArrowCommandIsExecuted() { VideoAsset videoAsset = new VideoAsset { Title = "VideoAsset" }; AudioAsset audioAsset = new AudioAsset { Title = "AudioAsset" }; FolderAsset folderAsset = new FolderAsset { Title = "ParentFolder" }; folderAsset.AddAssets(new ObservableCollection <Asset> { videoAsset, audioAsset }); var presentationModel = this.CreatePresentationModel(); this.assetsAvailableEvent.SubscribeArgumentAction.Invoke(new Infrastructure.DataEventArgs <List <Asset> >(new List <Asset> { folderAsset })); presentationModel.OnAssetSelected(folderAsset); Assert.AreEqual(2, presentationModel.Assets.Count); presentationModel.UpArrowCommand.Execute(null); Assert.AreEqual(1, presentationModel.Assets.Count); }
public void ShouldShowAllAssets() { var imageAsset = new ImageAsset { Title = "Image" }; var videoAsset = new VideoAsset { Title = "Video" }; var audioAsset = new AudioAsset { Title = "Audio" }; var assets = new List <Asset> { imageAsset, videoAsset, audioAsset }; var presentationModel = this.CreatePresentationModel(); this.assetsAvailableEvent.SubscribeArgumentAction.Invoke(new Infrastructure.DataEventArgs <List <Asset> >(assets)); presentationModel.ShowImages = false; presentationModel.ShowVideos = false; presentationModel.ShowAudio = false; Assert.AreEqual(0, presentationModel.Assets.Count); presentationModel.ShowImages = true; presentationModel.ShowVideos = true; presentationModel.ShowAudio = true; Assert.AreEqual(3, presentationModel.Assets.Count); }
public void ShouldShowOnlyTheTopLevelAssetsAtStart() { VideoAsset videoAsset = new VideoAsset() { Title = "VideoAsset" }; FolderAsset parentFolderAsset = new FolderAsset() { Title = "ParentFolder" }; FolderAsset childFolderAsset1 = new FolderAsset() { Title = "Child1Folder", ParentFolder = parentFolderAsset }; FolderAsset childFolderAsset2 = new FolderAsset() { Title = "Child1Folder", ParentFolder = parentFolderAsset }; parentFolderAsset.Assets.Add(childFolderAsset1); parentFolderAsset.Assets.Add(childFolderAsset2); var presentationModel = this.CreatePresentationModel(); presentationModel.Assets = new List <Asset> { videoAsset, parentFolderAsset }; Assert.IsTrue(presentationModel.Assets.Count == 2); }
public void ShouldAddDefaultOptionToAssetWithoutAudioStreams() { var viewModel = this.CreateViewModel(); VideoAsset asset = new VideoAsset(); viewModel.Asset = asset; Assert.AreEqual(1, viewModel.AvailableAudioStreams.Count); Assert.AreEqual("Default", viewModel.AvailableAudioStreams[0].Name); }
public void ShouldPublishEventWhenCallingOnAddAsset() { var asset = new VideoAsset(); var presentationModel = this.CreatePresentationModel(); Assert.IsFalse(this.addAssetEvent.PublishCalled); Assert.IsNull(this.addAssetEvent.Asset); presentationModel.OnAddAsset(asset); Assert.IsTrue(this.addAssetEvent.PublishCalled); Assert.IsNotNull(this.addAssetEvent.Asset); Assert.AreEqual(this.addAssetEvent.Asset, asset); }
public void ShouldSetShowMetadataToTrueWhenShowMetadataEventIsPublished() { var presentationModel = this.CreateMetadataViewPresentationModel(); Asset asset = new VideoAsset { Title = "Test Video" }; presentationModel.ShowMetadataInformation = false; this.showMetadataEvent.SubscribeArgumentAction(asset); Assert.IsTrue(presentationModel.ShowMetadataInformation); }
private static AssetItem ImportVideo([NotNull] UFile sourcePath, [NotNull] VideoStream videoStream) { var videoAsset = new VideoAsset { Source = sourcePath, }; videoAsset.VideoDuration.StartTime = TimeSpan.Zero; videoAsset.VideoDuration.EndTime = videoStream.Duration; var videoUrl = new UFile(sourcePath.GetFileNameWithoutExtension()); return(new AssetItem(videoUrl, videoAsset)); }
public void ShouldPublishShowMetadataEventWhenShowMetadataIsCalledAndAssetIsVideoAsset() { VideoAsset asset = new VideoAsset { Title = "Video" }; var presentationModel = this.CreatePresentationModel(); this.showMetadataEvent.PublishCalled = false; this.showMetadataEvent.Asset = null; presentationModel.ShowMetadata(asset); Assert.IsTrue(this.showMetadataEvent.PublishCalled); Assert.IsTrue(this.showMetadataEvent.Asset == asset); }
public void ShouldUpdateHasAssetWhenExecutingDropCommand() { var viewModel = this.CreateViewModel(); DropPayload dropPayload = new DropPayload(); VideoAsset asset = new VideoAsset(); dropPayload.DraggedItem = asset; Assert.IsFalse(viewModel.HasAsset); viewModel.DropCommand.Execute(dropPayload); Assert.IsTrue(viewModel.HasAsset); }
public void ShouldPublishAddAssetEventWhenExecutingAddItemCommand() { var asset = new VideoAsset(); var presentationModel = this.CreatePresentationModel(); Assert.IsFalse(this.addAssetEvent.PublishCalled); presentationModel.Assets = new List <Asset> { asset }; presentationModel.AddItemCommand.Execute(asset.Id); Assert.IsTrue(this.addAssetEvent.PublishCalled); Assert.AreEqual(asset, this.addAssetEvent.Asset); }
public void ShouldUpdateCurrentAssetWhenExecutingDropCommand() { var viewModel = this.CreateViewModel(); DropPayload dropPayload = new DropPayload(); VideoAsset asset = new VideoAsset(); dropPayload.DraggedItem = asset; Assert.IsNull(viewModel.Asset); viewModel.DropCommand.Execute(dropPayload); Assert.IsNotNull(viewModel.Asset); Assert.AreSame(asset, viewModel.Asset); }
public void ShouldPublishPlayerEventWhenExecutingPlaySelectedAssetCommandForVideoAsset() { var asset = new VideoAsset(); var presentationModel = this.CreatePresentationModel(); Assert.IsFalse(this.playerEvent.PublishCalled); Assert.IsNull(this.playerEvent.PublishArgumentPayload); presentationModel.Assets = new List <Asset> { asset }; presentationModel.PlaySelectedAssetCommand.Execute(asset.Id); Assert.IsTrue(this.playerEvent.PublishCalled); Assert.IsNotNull(this.playerEvent.PublishArgumentPayload); Assert.AreEqual(this.playerEvent.PublishArgumentPayload.Asset, asset); }
/// <summary> /// Creates a video asset for testing. /// </summary> /// <returns>A video asset with values.</returns> private static VideoAsset CreateVideoAsset() { var item = new VideoAsset(); item.ProviderUri = CreateUri(); item.Source = CreateUri(); item.Title = "Title"; item.ResourceType = ResourceType.Master; item.FrameRate = SmpteFrameRate.Smpte2997NonDrop; item.Height = 200; item.Width = 200; item.Duration = TimeCode.FromSeconds(60d, item.FrameRate); item.Metadata = new List <MetadataField> { new MetadataField("TestName", "TestValue") }; item.ThumbnailSource = "http://test1/test.png"; return(item); }
public void ShouldPublishShowMetadataEventWhenShowMetadataIsCalledAndAssetIsVideoAsset() { VideoAsset asset = new VideoAsset { Title = "Video" }; var presentationModel = this.CreatePresentationModel(); this.showMetadataEvent.PublishCalled = false; this.showMetadataEvent.Payload = null; var payload = new TimelineElement { Asset = asset }; presentationModel.ShowMetadata(payload); Assert.IsTrue(this.showMetadataEvent.PublishCalled); Assert.IsTrue(this.showMetadataEvent.Payload == payload); }
/// <summary> /// Adds the asset to timeline. /// </summary> private void AddAssetToTimeline() { Asset selectedAsset = this.AssetsList.SelectedItem as Asset; if (selectedAsset != null && !(selectedAsset is FolderAsset)) { if (selectedAsset is VideoAsset) { // VideoPreview preview = this.AssetsList.GetChildControls<VideoPreview>().Where(x => x.Asset == selectedAsset).Single(); VideoPreview preview = this.AssetsList.GetChildControls <VideoPreview>().Where(x => x.Asset == selectedAsset).Single(); VideoAsset videoAsset = selectedAsset as VideoAsset; VideoAssetInOut videoAssetInOut = new VideoAssetInOut(videoAsset); this.Model.AddAssetToTimeline(videoAssetInOut); } else { this.Model.AddAssetToTimeline(selectedAsset); } } }
public void ShouldUpdateTitleWhenAssetChanges() { var viewModel = this.CreateViewModel(); Assert.AreEqual("Sub-Clip Tool", viewModel.Title); VideoAsset asset = new VideoAsset(); asset.Title = "Asset Title"; bool wasCalled = false; string expectedTitle = string.Format("Source: {0}", asset.Title); viewModel.TitleUpdated += (s, a) => { wasCalled = true; }; viewModel.Asset = asset; Assert.AreEqual(expectedTitle, viewModel.Title); Assert.IsTrue(wasCalled); }
/// <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); // } }
public void ShouldCallHidePreviewImageMethodOfViewIfPlayerEventIsTriggeredFormTimelineModel() { var asset = new VideoAsset { Source = new Uri("http://test") }; var presenter = this.CreatePresenter(); this.view.HidePreviewImageCalled = false; Assert.IsFalse(this.view.SetSourceCalled); Assert.IsNull(this.view.SetSourceArgument); this.playerEvent.SubscribeArgumentAction(new PlayerEventPayload { Asset = asset, PlayerMode = PlayerMode.MediaBin }); Assert.IsTrue(this.view.SetSourceCalled); Assert.AreEqual(asset.Source, this.view.SetSourceArgument); Assert.IsTrue(this.view.HidePreviewImageCalled); }
public void ShouldPopulateOverlaysListWhenAssetsAvailableEventIsPublished() { var vm = this.CreateViewModel(); OverlayAsset o1 = new OverlayAsset(); OverlayAsset o2 = new OverlayAsset(); AudioAsset a1 = new AudioAsset(); VideoAsset v1 = new VideoAsset(); var assets = new List <Asset> { o1, o2, a1, v1 }; Assert.AreEqual(0, vm.Overlays.Count); this.assetsAvailableEvent.Publish(new DataEventArgs <List <Asset> >(assets)); Assert.AreEqual(2, vm.Overlays.Count); CollectionAssert.Contains(vm.Overlays, o1); CollectionAssert.Contains(vm.Overlays, o2); }
/// <summary> /// Returns the best fit size for the asset in the given size. /// </summary> /// <param name="width">Max possible width.</param> /// <param name="height">Max possible height.</param> /// <returns>Returns the best fit size for the asset.</returns> private Size GetSizeMaintainingAspectRatio(double width, double height) { width -= MarginX; if (width <= 0) { width = 1; } height -= MarginY; if (height <= 0) { height = 1; } VideoAsset videoAsset = this.Asset as VideoAsset; if (videoAsset != null) { double aspectRatioWidth = Convert.ToDouble(videoAsset.Width.GetValueOrDefault()); double aspectRatioHeight = Convert.ToDouble(videoAsset.Height.GetValueOrDefault()); if (aspectRatioWidth == 0 || aspectRatioHeight == 0) { return(new Size(width, height)); } if (width >= height * aspectRatioWidth / aspectRatioHeight) { return(new Size(height * aspectRatioWidth / aspectRatioHeight, height)); } else { return(new Size(width, width * aspectRatioHeight / aspectRatioWidth)); } } return(new Size(width, height)); }
public void ShouldSetShowMetadataToTrueWhenShowMetadataEventIsPublished() { this.regionManager.Regions.Add(new MockRegion { Name = RegionNames.ClipMetadataRegion }); var presentationModel = this.CreateMetadataViewPresentationModel(); Asset asset = new VideoAsset { Title = "Test Video" }; presentationModel.ShowMetadataInformation = false; var payload = new TimelineElement { Asset = asset }; this.showMetadataEvent.SubscribeArgumentAction(payload); Assert.IsTrue(presentationModel.ShowMetadataInformation); }
public void ShouldReturnTheAssetAssociatedWithTheMediaDataUnderTheCurrentPosition() { var aggregateMediaModel = CreateTestableAggregateMediaModel(); var expectedAsset = new VideoAsset { Source = new Uri("http://test") }; var timelineElement1 = new TimelineElement { Asset = new ImageAsset(), InPosition = TimeCode.FromSeconds(0d, SmpteFrameRate.Smpte25), OutPosition = TimeCode.FromSeconds(5000d, SmpteFrameRate.Smpte25), Position = TimeCode.FromSeconds(0d, SmpteFrameRate.Smpte25) }; var timelineElement2 = new TimelineElement { Asset = expectedAsset, InPosition = TimeCode.FromSeconds(0d, SmpteFrameRate.Smpte25), OutPosition = TimeCode.FromSeconds(5000d, SmpteFrameRate.Smpte25), Position = TimeCode.FromSeconds(1000d, SmpteFrameRate.Smpte25) }; aggregateMediaModel.AddElement(timelineElement1); aggregateMediaModel.AddElement(timelineElement2); // Set the current media. aggregateMediaModel.Position = TimeSpan.FromSeconds(6000); Assert.AreEqual(expectedAsset, aggregateMediaModel.CurrentAsset); }
public void ShouldNotifyHasAssetPropertyChangedWhenAssetChanges() { var viewModel = this.CreateViewModel(); VideoAsset asset1 = new VideoAsset(); VideoAsset asset2 = new VideoAsset(); int timesRaised = 0; viewModel.PropertyChanged += (s, a) => { if (a.PropertyName == "HasAsset") { timesRaised++; } }; viewModel.Asset = asset1; viewModel.Asset = asset1; viewModel.Asset = asset2; viewModel.Asset = asset2; Assert.AreEqual(2, timesRaised); }
/// <summary> /// Sets the source of the <see cref="Player"/> in case of Audio/Video asset /// and set the <see cref="PreviewImage"/> source in case of image asset. /// </summary> /// <param name="asset">The asset.</param> public void SetSource(Asset asset) { this.Stop(); // Set the size of the media element maintaining the aspect ratio. VideoAsset videoAsset = asset as VideoAsset; if (videoAsset != null) { Size size = this.CalculatePlayerSize(videoAsset.Width.GetValueOrDefault(), videoAsset.Height.GetValueOrDefault()); this.Player.Width = size.Width; this.Player.Height = size.Height; } if (asset is ImageAsset) { this.Player.Opacity = 0; this.PreviewImage.Source = new BitmapImage(asset.Source); this.PreviewImage.Opacity = 1; } else { this.PreviewImage.Opacity = 0; if (asset.IsAdaptiveAsset) { this.Player.SmoothStreamingSource = asset.Source; } else { this.Player.Source = asset.Source; } this.Player.Opacity = 1; } }
public void ShouldClearOverlaysListBeforeAddingAssetsWhenAssetsAvailableEventIsPublished() { var vm = this.CreateViewModel(); OverlayAsset o1 = new OverlayAsset(); OverlayAsset o2 = new OverlayAsset(); AudioAsset a1 = new AudioAsset(); VideoAsset v1 = new VideoAsset(); var assets = new List <Asset> { o1, o2, a1, v1 }; Assert.AreEqual(0, vm.Overlays.Count); this.assetsAvailableEvent.Publish(new DataEventArgs <List <Asset> >(assets)); Assert.AreEqual(2, vm.Overlays.Count); CollectionAssert.Contains(vm.Overlays, o1); CollectionAssert.Contains(vm.Overlays, o2); OverlayAsset o3 = new OverlayAsset(); OverlayAsset o4 = new OverlayAsset(); AudioAsset a2 = new AudioAsset(); VideoAsset v2 = new VideoAsset(); var newAssets = new List <Asset> { o3, o4, a2, v2 }; this.assetsAvailableEvent.Publish(new DataEventArgs <List <Asset> >(newAssets)); Assert.AreEqual(2, vm.Overlays.Count); CollectionAssert.Contains(vm.Overlays, o3); CollectionAssert.Contains(vm.Overlays, o4); }
public void ShouldReadMetadataAndPopulateAssetMetadataDetails() { this.configurationService.GetParameterValueReturnFunction = parameter => { if (parameter == "MetadataFields") { return("Title;Duration;FrameRate"); } return(null); }; var presentationModel = this.CreateMetadataViewPresentationModel(); Asset asset = new VideoAsset { Title = "Test Video" }; Assert.IsNull(presentationModel.AssetMetadataDetails); this.showMetadataEvent.SubscribeArgumentAction(asset); Assert.AreEqual(3, presentationModel.AssetMetadataDetails.Count); }
public void InsertOrUpdateVideoAsset(VideoAsset videoAsset) { _context.Entry(videoAsset).State = videoAsset.VideoAssetID == 0 ? EntityState.Added : EntityState.Modified; _context.SaveChanges(); }