This is a migrated thread and some comments may be shown as answers.

MediaPlayer in ASPNET AJAX Window keeps playing after window is closed

3 Answers 158 Views
MediaPlayer
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 2
Mark asked on 28 Aug 2010, 08:00 PM
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

3 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 01 Sep 2010, 03:53 PM
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
0
Mark
Top achievements
Rank 2
answered on 04 Sep 2010, 03:11 AM
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?
0
Mark
Top achievements
Rank 2
answered on 04 Sep 2010, 04:20 AM
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
Tags
MediaPlayer
Asked by
Mark
Top achievements
Rank 2
Answers by
Kiril Stanoev
Telerik team
Mark
Top achievements
Rank 2
Share this question
or