Skip to content

Commit e6d02d0

Browse files
committed
kb(mediaplayer): add article show media player in window
1 parent 389d9af commit e6d02d0

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
title: Media Player inside Window
3+
description: Learn how to add a Media Player inside a Window
4+
type: how-to
5+
page_title: Media Player inside Window. | RadWindow
6+
slug: mediaplayer-inside-window
7+
tags: window, media player, media player inside window
8+
ticketid: 1654135
9+
res_type: kb
10+
---
11+
12+
## Environment
13+
<table>
14+
<tbody>
15+
<tr>
16+
<td>Product</td>
17+
<td>Telerik WebForms MediaPlayer for ASP.NET AJAX</td>
18+
</tr>
19+
</tbody>
20+
</table>
21+
22+
23+
## Description
24+
25+
Sometimes, you might want to show a MediaPlauer with a video on it, after the press of a button.
26+
27+
## Solution
28+
29+
To do that, you can use the Window control and add a MediaPlayer as its template.
30+
31+
32+
````ASP.NET
33+
<telerik:RadWindowManager ID="RadWindowManager1" runat="server" />
34+
<telerik:RadButton runat="server" ID="RadButton1" Text="Postback" AutoPostBack="true" OnClick="RadButton1_Click" />
35+
````
36+
37+
````C#
38+
protected void RadButton1_Click(object sender, EventArgs e)
39+
{
40+
RadWindow window = new RadWindow()
41+
{
42+
ID = "PlayerWindow",
43+
VisibleOnPageLoad = true,
44+
Width = 950,
45+
Height = 500,
46+
OnClientShow = "onClientShow",
47+
OnClientBeforeClose = "onClientBeforeClose",
48+
ContentTemplate = new WindowMediaTemplate("MediaPlayer1"),
49+
};
50+
51+
RadWindowManager1.Windows.Add(window);
52+
}
53+
54+
private class WindowMediaTemplate : ITemplate
55+
{
56+
protected RadMediaPlayer player;
57+
private string _id;
58+
59+
public WindowMediaTemplate(string id)
60+
{
61+
_id = id;
62+
}
63+
64+
public void InstantiateIn(Control container)
65+
{
66+
player = new RadMediaPlayer()
67+
{
68+
ID = _id,
69+
Height = Unit.Pixel(360),
70+
Width = Unit.Pixel(640),
71+
BannerCloseButtonToolTip = "Close",
72+
Title = "Getting Started with the JoT ERP",
73+
Playlist =
74+
{
75+
new MediaPlayerVideoFile()
76+
{
77+
Path="https://www.youtube.com/watch?v=9M2zYspl9e0",
78+
Title="Cat mewing",
79+
Poster="~/Images/cat1.jpg"
80+
},
81+
new MediaPlayerVideoFile()
82+
{
83+
Path="https://www.youtube.com/watch?v=kG7d_4LeP48",
84+
Title="Cat says hi",
85+
Poster="~/Images/cat2.jpg"
86+
},
87+
}
88+
};
89+
container.Controls.Add(player);
90+
}
91+
}
92+
````
93+
94+
- The [`onClientShow`]({%slug window/client-side-programming/events/onclientshow%}) event is used to remove any inactive windows after they are shown.
95+
- The [`onClientBeforeClose`]({%slug window/client-side-programming/events/onclientbeforeclose%}) event is used to pause the MediaPlayer whenever the Window is closed.
96+
97+
````JavaScript
98+
function onClientShow(sender, args) {
99+
var windows = document.querySelectorAll(".rwInactiveWindow"); // Get a reference to all the inactive windows
100+
101+
windows.forEach(function (window) {
102+
var windowToHide = window.id.replace('RadWindowWrapper_', ''); // We remvoe the windows because every time the button is clicked, a new window is created
103+
var radWindow = $find(windowToHide); // Find the RadWindows (to see what we actually dispose, comment the code in the event)
104+
105+
if (radWindow) {
106+
radWindow.dispose(); // Dispose the
107+
}
108+
});
109+
}
110+
111+
function onClientBeforeClose(sender, args) {
112+
var windowContent = sender.get_contentElement(); // Get the content of the RadWindow
113+
var mediaPlayer = $(windowContent).find(".RadMediaPlayer")[0].control; // Find the MediaPlayer control
114+
115+
mediaPlayer.pause(); // Pause it when closing the player
116+
}
117+
````
118+
119+
120+
121+

0 commit comments

Comments
 (0)