views:

1245

answers:

3

Hello everyone,

I am using VSTS 2008 with C# to develop Silverlight application embedded in web page of an ASP.Net web application. I have embedded in XAML a MediaElement item. My question is, I want to embed the page a Silverlight media player, which could let end user to control the MediaElement item manually to -- play/pause/stop/rewind/forward. Are there any references samples?

thanks in advance, George

EDIT1: add more accurate requirements,

Actually, I want to control play manually, which means I want to handle the player play/pause/stop/rewind/forward events and add my code for the event handlers to control the MediaElement and do something else.

EDIT2: My needs are, I want to play two overlapped video. Screen as background video and camera as foreground video (place at right bottom corner). Here is my modification of code, my current issue is, only background video is played, foreground right bottom video is never played. Does anyone have any ideas why?

BTW: my modified code and current work is based on http://www.codeplex.com/sl2videoplayer

http://www.yourfilehost.com/media.php?cat=other&file=sl2videoplayer_24325_new.zip

Here is a brief description of my major modified code,

mediaControls.xaml.cs

private MediaElement _media = null;
private MediaElement _camera = null;

public MediaElement Camera
{
    set
    {
        _camera = value;
    }
}

void btnPlay_Checked(object sender, RoutedEventArgs e)
{
    _camera.Play();            
    _media.Play();
    OnPlayClicked();
}

Page.xaml

    <MediaElement HorizontalAlignment="Stretch" Margin="0,0,0,0" x:Name="mediaPlayer" Stretch="Uniform" VerticalAlignment="Stretch" AutoPlay="false"/>
    <MediaElement Width="100" Height="100" x:Name="cameraPlayer" AutoPlay="false" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>

Page.xaml.cs

cameraPlayer.Source = App.Current.Resources["c"] as Uri;

App.xaml.cs (Application_Startup function)

        else if (item.Key.ToLower() == "c")
        {
            FormatUri(e.InitParams["c"].ToString(), "c", false);
        }

default.html

  <param name="initParams" value="cc=true,markers=true,markerpath=markers_movie21.xml,m=http://localhost/screen.wmv,c=http://localhost/camera.wmv" />
+4  A: 

Oh baby have I got the media player for you: Sl2 Video Player. MSPL open sourced and awesome.

To add the ability to control the player pragmatically, add ScriptableMembers. You'll see the registration statement already in the code:

    HtmlPage.RegisterScriptableObject("Page", page);

Now look at an example ScriptableMember:

[ScriptableMember]
public void SeekPlayback(string time)
{
    TimeSpan tsTime = TimeSpan.Parse(time);
    mediaControls.Seek(tsTime);
}

already exists in the code. Add more methods to do what you want to have happen. Then you can call the methods from managed code in another SL player:

HtmlElement videoPlugin = HtmlPage.Document.GetElementById("VideoPlayer");
            if (videoPlugin != null)
            {
                ScriptObject mediaPlayer = (ScriptObject)((ScriptObject)videoPlugin.GetProperty("Content")).GetProperty("Page");

                mediaPlayer.Invoke("SeekPlayback", TimeSpan.FromSeconds(seconds).ToString());

            }

or from javascript:

        var sl = document.getElementById("VideoPlayer");
        var content = sl.Content.Page;
        content.SeekPlayback('55');
Erik Mork
Silverlight designer in VSTS 2008 does not have built-in media player control?
George2
@Erik, the player you recommend can not achieve all of my goals. Actually, I want to control play manually, which means I want to handle the player play/pause/stop/rewind/forward events and add my code for the event handlers. Any ideas?
George2
You want to control play from outside of the player? The Html bridge is for you :) I'll edit to add the details.
Erik Mork
Also, if you want to wire up your code inside of the video player, take a look at the Page's mediaControls member. It has the Media property which gives direct access to the MediaElement so you can customize all you want.
Erik Mork
@Erik, a new question, I am reading the code, and there are 3 player related projects, videoplayer, mediaplayer and videoplayerthemed, what are the differences between them and what are their individual relationship between VideoPlayerWeb web site project?
George2
@Erik, I read related code and did not find code where media is controlled to play/stop/pause/rewind/forward. Any hints which part of code to read?
George2
The "VideoPlayer" project is all you need. Run the default.html file in the VideoPlayerWeb to see it in action.As to the control issue, you need access to the MediaElement class ( http://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement(VS.95).aspx ) to call the Play/Pause etc. methods. This can be found (inside of the Page.xaml.cs file) here: this.mediaControls.Media . HTH
Erik Mork
Thanks Erik, appreciate if you could describe what are the differences between videoplayer, mediaplayer and videoplayerthemed and what are their individual relationship between VideoPlayerWeb web site project? I did not find related documents from the project web site. I think the more I know, the more I can understand the whole picture. Even if currently I only need a part of function from video player project, but I think knowing the whole picture will benefit me in the future.
George2
I think the videoplayerthemed is just a themed version of the default player. I'm not sure what the mediaplayer project is. Just unload those projects from the solution and don't worry about them for a while :) The web site project is for hosting the silverlight control. It has different pages for hosting the different players. Default.html is the one you want to start.
Erik Mork
Thanks! I met with an issue when starting this project, I have started a separate thread to discuss this dedicated issue, any ideas what is wrong?http://stackoverflow.com/questions/990033/unable-to-connect-to-asp-net-development-server-issue
George2
@Erik, I have solved this issue by restarting machine. I take some time to debug video player and my current confusion is where is the code to control to start to play a media? Any hints? I am new to this open source project and feeling confusion when debugging the first time. :-)
George2
@Erik, I have solved issues from my side, but met with a new issue and posted in my original question with my modified code. Any ideas?
George2
Thanks @Erik, I have marked your reply as answered and appreciate your help. I have a similar question about sl2player here, http://stackoverflow.com/questions/1033331/thumbnail-image-of-siverlight-video any ideas?
George2
+1  A: 

If they are two seperate xap packages, there will be no way for the two to communicate since Silverlight sandboxes both individually.

Jason Watts
1. Any solutions to make them into one XAP package? 2. Silverlight designer in VSTS 2008 does not have built-in media player control?
George2
A: 

Guys,

SL2videoplayer says it supports streaming video. But when I try giving a media services broadcast url (OnDemand and Live) to init param 'm' nothing showed up. In the init param example page also a remote wmv file being played is shown.

Also are there any known issues of using this with SL 3?

Uchitha