MediaPlayer in ASPNET AJAX Window keeps playing after window is closed

4 posts, 0 answers
  1. Mark
    Mark avatar
    79 posts
    Member since:
    Apr 2007

    Posted 28 Aug 2010 Link to this post

    Hey Telerik Team,

    I'm using the Silverlight MediaPlayer in an ASPNET AJAX Window.  The window opens in modal mode and the media player works fine.  However, when the user closes the RadWindow, the media continues to play in the background (you can still hear audio).  This happens in IE 8 and Chrome, but not Firefox.  Is there a way to tell the media player to stop via JavaScript OnClose method of the window?

    Thanks,

    MJ
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 01 Sep 2010 Link to this post

    Hi MJ,

    Please have a look at this forum thread as it explains how to play and pause RadMediaPlayer from JavaScript. More information on JS-Managed Code bridge you can find here.


    Best wishes,
    Kiril Stanoev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Mark
    Mark avatar
    79 posts
    Member since:
    Apr 2007

    Posted 03 Sep 2010 Link to this post

    That makes sense and the examples work, but I think my case is a little different.  Since I'm using a RadWindow which is essentially an iFrame for the page that has the MediaPlayer, how does the parent page call "Pause" to a JS method loaded in the RadWindow?
  5. Mark
    Mark avatar
    79 posts
    Member since:
    Apr 2007

    Posted 03 Sep 2010 Link to this post

    Okay, I think I've got it.  I used the links you mentioned to implement a jQuery solution.  Using jQuery in the child window, I get a reference to the parent and attach to the click event of the close button:

    Here's the jQuery that goes in the page that the RadWindow loads:

    <script type="text/javascript">
        $(document).ready(function () {
            var oBrowserWnd = GetRadWindow().BrowserWindow;
     
            var closeButton = $("a[class$=rwCloseButton]", oBrowserWnd.document);
            closeButton.click(function () {
                StopMedia();
            });
     
            function StopMedia() {
                var btMediaPlayer = document.getElementById("slMediaPlayer");
                btMediaPlayer.Content.MPSH.StopMedia();
            }
        });
    </script>

    GetRadWindow() is a javascript method I have in another common.js file in my site.  I borrowed the logic from Telerik to get a reference to the parent window.  It looks like this:

    function GetRadWindow() {
        var oWindow = null;
        if (window.radWindow) oWindow = window.radWindow;
        else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
        return oWindow;
    }


    slMediaPlayer is the id of the Silverlight object (in markup on the aspx page loaded by the RadWindow).

    Lastly, the "MPSH" (MediaPlayerScriptHandler)  is in my Silverlight project and looks like this:

    public partial class MediaPlayer : System.Windows.Controls.UserControl
        {
            public MediaPlayer()
            {
                InitializeComponent();
     
                MediaPlayerScriptHandler mpsh = new MediaPlayerScriptHandler(mpBackingTracks);
                HtmlPage.RegisterScriptableObject("MPSH", mpsh);
     
            }
        }


    namespace Gv.Silverlight
    {
        [ScriptableType]
        public class MediaPlayerScriptHandler
        {
            RadMediaPlayer player;
     
            public MediaPlayerScriptHandler(RadMediaPlayer player)
            {
                this.player = player;
            }
     
            [ScriptableMember]
            public void PlayMedia()
            {
                player.Play();
            }
     
            [ScriptableMember]
            public void PauseMedia()
            {
                player.Pause();
            }
     
            [ScriptableMember]
            public void StopMedia()
            {
                player.Stop();
            }
        }
    }


    Thanks for the help...it took a bit of struggling, but I pieced it together.  Hope this helps someone else who is implementing weird combinations of Telerik's controls like I am. :-)

    ~MJ
Back to Top