This topic explains how to query instances of videos. The examples below show you how to query all of the available videos or how to query only a specific video by its ID.
NOTE: The code examples below work with the ID of the master version of the video and return the live version of the video. For more information about other scenarios, see For developers: Query master and live versions.
When querying the live version of a specific video by the ID of its master version, you must perform the following:
The following code queries the live version of a video by the ID of its master version.
Video GetVideoNativeAPI(Guid masterVideoId)
LibrariesManager librariesManager = LibrariesManager.GetManager();
Video video = librariesManager.GetVideos().Where(d => d.Id == masterVideoId).FirstOrDefault();
video = librariesManager.Lifecycle.GetLive(video)
First, you get an instance of the LibrariesManager class. You get the specified video by querying all videos and filtering the collection by the ID property of the video. If the video exists, you get its live version. If no live version exists (i.e. the item has not been published), you return null. Finally, you return the live version.
You can also use the following code to retrieve the video:
Video video = librariesManager.GetVideo(masterVideoId);
Note that when the video does not exist, an exception of type ItemNotFoundException is thrown.
Video GetVideoFluentAPI(Guid masterVideoId)
First, you get the singular video facade of the master version with the specified ID. Then, to load the live version of the video, you call the GetLive method of the facade. Finally, to get the instance of the live version, you call the Get method.
To query videos by a video library, you must perform the following:
NOTE: Another way of getting the videos from a specific library, is to query all the videos and filter the collection by the ID of the video library. You can find an example of this approach in the next section.
Here is a code example:
IQueryable<Video> GetVideosByVideoLibraryNativeAPI(Guid videoLibraryId)
VideoLibrary videoLibrary = librariesManager.GetVideoLibrary(videoLibraryId);
videoLibrary.Videos().Where(v => v.Status == ContentLifecycleStatus.Live);
IQueryable<Video> GetVideosByVideoLibraryFluentAPI(Guid videoLibraryId)
App.WorkWith().VideoLibrary(videoLibraryId).Videos().Where(d => d.Status == ContentLifecycleStatus.Live).Get();
When querying all videos, you must perform the following:
The following code queries all published videos.
NOTE: You can filter the query to get a specific set of videos. For example, you can get the videos from a specific library:
List<Video> GetAllVideosByVideoLibraryNativeAPI(Guid videoLibraryId)
librariesManager.GetVideos().Where(d => d.Status == ContentLifecycleStatus.Live && d.Parent.Id == videoLibraryId).ToList();
In this code example you additionally filter the collection by the ID of the parent video library.
List<Video> GetAllVideosByVideoLibraryFluentAPI(Guid videoLibraryId)
App.WorkWith().Videos().Where(v => v.Parent.Id == videoLibraryId && v.Status == ContentLifecycleStatus.Live).Get().ToList();
In this code example you use the plural facade for the videos and filter them by the ID of the specified video library. Then, you get the live versions of the selected videos.
Back To Top