Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > MediaPlayer > Programmatically tell the media player to start playing

Not answered Programmatically tell the media player to start playing

Feed from this thread
  • Andrew avatar

    Posted on Aug 24, 2011 (permalink)

    I have a web page which contains a silverlight control that hosts a RadMediaPlayer.
    Javascript on the web page can tell the RadMediaPlayer to start playing a particular file.

    This is almost working, except it won't start playing automatically. The user still has to press the start button.

    Why doesn't RadMediaPlayer.Play() start it?

    Edit: The first time my function PlayMediaFile is called, it does not start by itself. The second time my function is called, it DOES start (even if the user had not pressed the start button the first time, and even if it's a different media file then the first time).


    Here is the code:

    [ScriptableMember(ScriptAlias="playMediaFile")]
    public void PlayMediaFile(long entityId, string fileName)
    {
        try
        {
            _tbDebugOutput.Text = string.Format("PlayMediaFile({0}, {1}", entityId, fileName);
            SetPlaylist(entityId, fileName);
             this._radMediaPlayer.Play(); // This should start it playing! But it doesn't.
        }
        catch (Exception ex)
        {
            this._tbDebugOutput.Text = ex.ToString();
        }
    }
     
    public void SetPlaylist(long entityId, string fileName)
    {
        var path = GenerateMediaFilePath(entityId, fileName);
        RadMediaItem mediaItem = new RadMediaItem();
        mediaItem.Source = new Uri(path, UriKind.RelativeOrAbsolute);
        this._radMediaPlayer.Items.Clear();
        this._radMediaPlayer.Items.Add(mediaItem);
    }

    Reply

  • Andrew avatar

    Posted on Aug 26, 2011 (permalink)

    I replaced the direct call to "Play" to a posted dispatcher call. Now it works.


    [ScriptableMember(ScriptAlias="playMediaFile")]
    public void PlayMediaFile(long entityId, string fileName)
    {
        try
        {
            this._radMediaPlayer.AutoPlay = true;
            SetPlaylist(entityId, fileName);
            this.Dispatcher.BeginInvoke(new Action(() => this._radMediaPlayer.Play()));
        }
        catch (Exception ex)
        {
            this._tbDebugOutput.Text = ex.ToString();
        }
    }

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > MediaPlayer > Programmatically tell the media player to start playing
Related resources for "Programmatically tell the media player to start playing"

Silverlight MediaPlayer Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]