ASP.NET Core MediaPlayer Overview
The MediaPlayer is part of Telerik UI for ASP.NET Core, a
professional grade UI library with 110+ components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.
The Telerik UI MediaPlayer TagHelper and HtmlHelper for ASP.NET Core are server-side wrappers for the Kendo UI MediaPlayer widget.
The MediaPlayer plays video files from static sources or streams online YouTube videos and enriches your website with dynamic content in a user-friendly interface. It provides a styled video UI functionality by using the HTML5 <video>
element and brings powerful media capabilities to your applications without the necessity of installing additional plug-ins.
To respond to cutting-end design practices and trends, the MediaPlayer component provides a responsive layout. This means that its size adapts depending on the capabilities of the client (end user) device and browser. The component automatically resizes its area to display the video in the most suitable possible way within the provided dimensions. The responsive web design of the MediaPlayer is shipped out-of-the-box and intends to save you time and efforts when developing your responsive applications.
The following image demonstrates a template of the MediaPlayer.
Initializing the MediaPlayer
Once your video files are ready, initialize the MediaPlayer. It will render a div
element as its wrapper container.
The following example uses the autoPlay
property:
- Because of the mobile considerations, browsers on iOS do not automatically play embedded media. This limitation prevents unsolicited downloads over cellular networks at the expense of the user. The user always has to initiate a playback. For more information, refer to the article on audio and video HTML.
- Other functionalities may also be limited due to iOS restrictions. For more information, refer to this article and to other available resources on the Web.
@(Html.Kendo().MediaPlayer()
.Name("mediaplayer")
.AutoPlay(true)
.Navigatable(true)
.Media(m => m
.Title("Our Company Culture - Lesson 1")
.Source("Video/video1.mp4")
)
.HtmlAttributes(new { style = "height:360px; width:640px" })
)
<kendo-mediaplayer name="mediaplayer"
auto-play="true"
navigatable="true"
style = "height:360px; width:640px">
<media title="Our Company Culture - Lesson 1" source="Video/video1.mp4" />
</kendo-mediaplayer>
Basic Configuration
The following example demonstrates the basic configuration of the MediaPlayer.
@(Html.Kendo().MediaPlayer()
.AutoPlay(true) // Start playing the video as soon as it loads.
.Navigatable(true) // Enable the keyboard navigation.
.AutoRepeat(true) // Loop the video.
.ForwardSeek(false) // Disable forward seeking to ensure viewers will watch the entire video.
.FullScreen(false) // When set to true, the player will automatically enter the full-screen mode.
.Mute(true) // Start without sound.
.Volume(20) // Preset the volume level (0 - 100).
.Media(m => m // Define the media file - a YouTube video in this case.
.Title("Getting Started with Telerik UI for ASP.NET Core on Windows")
.Source("https://www.youtube.com/watch?v=AIFNeWrZCdM")
)
.Name("mediaPlayer") // The name of the widget that is used for the ID and for referencing it at runtime.
.HtmlAttributes(new { style = "height:360px; width:640px" })
)
<kendo-mediaplayer
name="mediaplayer"
auto-play="true"
navigatable="true"
auto-repeat="true"
forward-seek="false"
full-screen="false"
mute="true"
volume="20"
style = "height:360px; width:640px">
<media title="Our Company Culture - Lesson 1" source="Video/video1.mp4" />
</kendo-mediaplayer>
Functionality and Features
- Adding multiple sources—You can set different sources to the component simultaneously.
- Globalization—The MediaPlayer provides localization capability.
- Accessibility—The component was designed with accessibility in mind.
Events
You can subscribe to all MediaPlayer events. For a complete example on basic MediaPlayer events, refer to the demo on using the events of the MediaPlayer.
Handling by Handler Name
The following example demonstrates how to subscribe to events by using a handler name.
@(Html.Kendo().MediaPlayer()
.Name("mediaplayer")
.AutoPlay(true)
.Events(e =>
{
e.Pause("playerPause");
e.VolumeChange("playerVolumeChange");
})
.Media(m => m
.Title("Our Company Culture - Lesson 1")
.Source("Video/video1.mp4")
)
.HtmlAttributes(new { style = "height:360px; width:640px" })
)
<kendo-mediaplayer name="mediaplayer"
auto-play="true"
on-pause="playerPause"
on-volume-change="playerVolumeChange"
style = "height:360px; width:640px">
<media title="Our Company Culture - Lesson 1" source="Video/video1.mp4" />
</kendo-mediaplayer>
<script>
function playerPause(e) {
// Handle the pause event.
}
function playerVolumeChange(e) {
// Handle the volumeChange event.
}
</script>
Handling by Template Delegate
The following example demonstrates how to subscribe to events by using a template delegate.
@(Html.Kendo().MediaPlayer()
.Name("mediaplayer")
.AutoPlay(true)
.Events(e =>
e.Pause(@<text>
function(e) {
// Handle the pause event inline.
}
</text>)
.VolumeChange(@<text>
function(e) {
// Handle the volumeChange event inline.
}
</text>)
)
.Media(m => m
.Title("Our Company Culture - Lesson 1")
.Source("Video/video1.mp4")
)
.HtmlAttributes(new { style = "height:360px; width:640px" })
)
Referencing Existing Instances
To reference an existing MediaPlayer instance, use the jQuery.data()
configuration option. Once a reference is established, use the MediaPlayer client-side API to control its behavior.
@(Html.Kendo().MediaPlayer()
.Name("mediaplayer")
.AutoPlay(true)
.Media(m => m
.Title("Our Company Culture - Lesson 1")
.Source("Video/video1.mp4")
)
.HtmlAttributes(new { style = "height:360px; width:640px" })
)
<button onclick="buttonClick();">Pause Video</button>
<script>
function buttonClick() {
var player = $("#mediaplayer").data("kendoMediaPlayer");
player.pause();
}
</script>
<kendo-mediaplayer name="mediaplayer"
auto-play="true"
style = "height:360px; width:640px">
<media title="Our Company Culture - Lesson 1" source="Video/video1.mp4" />
</kendo-mediaplayer>
<button onclick="buttonClick();">Pause Video</button>
<script>
function buttonClick() {
var player = $("#mediaplayer1").data("kendoMediaPlayer");
player.pause();
}
</script>
Next Steps
- Getting Started with the MediaPlayer
- Basic Usage of the MediaPlayer for ASP.NET Core (Demo)
- Multiple Sources