YouTube sound continues after closing

3 posts, 0 answers
  1. Rob
    Rob avatar
    6 posts
    Member since:
    Jan 2011

    Posted 15 Jan 2014 Link to this post

    Hi,
    I am using a RadWindow to display the RadMediaPlayer. It all works fine until I close the RadWindow; the sound track from the YouTube clip keeps playing. How can I stop the YouTube clip completely when the RadWindow is closed?
    Thanks
    Rob
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Jan 2014 Link to this post

    Hi Rob,

    Please try the following code snippet to achieve your scenario.

    ASPX:
    <telerik:RadWindow ID="RadWindow1" runat="server" VisibleOnPageLoad="true" OnClientBeforeClose="OnClientBeforeClose">
        <ContentTemplate>
            <telerik:RadMediaPlayer ID="RadMediaPlayer1" runat="server" HDActive="false" Width="700px"
                Height="500px" StartVolume="90" Source="http://www.youtube.com/watch?v=3FcCUXrR1-0">
            </telerik:RadMediaPlayer>
        </ContentTemplate>
    </telerik:RadWindow>

    JavaScript:
    <script type="text/javascript">
        function OnClientBeforeClose(sender, args) {
            var mediaplayer = $find("<%=RadMediaPlayer1.ClientID %>");
            mediaplayer.stop();
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rob
    Rob avatar
    6 posts
    Member since:
    Jan 2011

    Posted 16 Jan 2014 Link to this post

    Thanks, all working now. I had to make so small changes to allow the RadWindow to include external code i.e.
    From the initiating program:
    <script type="text/javascript">
     
                function ShowYouTube(url) {
                            window.radopen(url, "YouTubeRadWindow");
                            return false;
                }
        function OnClientBeforeClose(sender, args) {
            var oWnd = GetRadWindowManager().getWindowByName("YouTubeRadWindow");
            oWnd.get_contentFrame().contentWindow.CloseYouTube();                       
        }
     
    </script>

    <telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="True"
                    Animation="Fade" VisibleStatusbar="False" Behaviors="Close, Move" Skin="Default"
                    ShowContentDuringLoad="False" KeepInScreenBounds="True">
         <Windows>
              <telerik:RadWindow ID="YouTubeRadWindow" runat="server" Width="670px" OnClientBeforeClose="OnClientBeforeClose"
                           Height="435px"  ShowContentDuringLoad="False" />
         </Windows>
    </telerik:RadWindowManager>

    Then this was in the called URL:

    <script type="text/javascript">
               function GetRadWindow() {
                   var oWindow = null;
                   if (window.radWindow) {
                       oWindow = window.radWindow;
                   }
                   else if (window.frameElement.radWindow) {
                       oWindow = window.frameElement.radWindow;
                   }
                   return oWindow;
               }
     
               function CloseDialog() {
                   GetRadWindow().Close();
               }
     
               function CloseYouTube() {
                   var mediaplayer = $find("<%=YouTubeMediaPlayer.ClientID %>");
                   mediaplayer.stop();               
               }
     
           </script>
        
       <div>
           <telerik:RadMediaPlayer ID="YouTubeMediaPlayer" runat="server" Width="640px" Height="360px"
               HDActive="false" />
       </div>

    Thanks again for the quick response.
    Cheers
Back to Top