locked
Advanced Media Player issues RRS feed

  • Question

  • I am kinda new to Silverlight, but I am tracking the development of the technology.

    So now I try to build an advanced media player and I've encountered some problems. As a template I am using the XAML file from Tim Heuer's blog - a cheat sheet for design. :)

    So now I am experiencing issues writing the controls on C#. So here is my Page.xaml.cs code:

    public void Page_Loaded(object o, EventArgs e)

    {

    // Required to initialize variables

    InitializeComponent();

    }

    // Handles Play/Pause button button

    // // My attribute for MouseLeftButtonDown is named btnPlayPause and my media element is named mPlayer

    public void btnPlayPause(object sender, EventArgs e)

        {

            if (mPlayer.CurrentState == mPlayer.Play())

        {

            mPlayer.Pause();

         }

         else{

                mPlayer.Play();

              }

    }

    // Handles Stop Button

    // My attribute for MouseLeftButtonDown is named btnStop

    public void btnStop(object sender, EventArgs e)

    {

         mPlayer.Stop();

    }

    Firstly I have had 3 buttons - play, pause and stop.

    Initially I've made the play and pause buttons separatelly and everything was fine - I just had different property for each button. Could somebody more advanced check my algorithm for handling Play/Pause button please?

    Of course I have set MouseLeftButtonDown attribute for the button elements. However, it seems I am doing something wrong, or that said I am getting the following message:

    Project file must include the .NET Framework assembly 'WindowsBase, PresentationCore, PresentationFramework' in the reference list.

    In addition, I am planning to make the loop sequence for looping the media files with LINQ. I have end up with something like that

    public void LINQ() {

            List<MEDIA> medias = GetMediaList();

            var mediaNames =

                  from m in medias

                  select m.MediaName;

     

                  Console.WriteLine("Media Names:");

                   foreach (var mediaName in mediaNames) {

                   Console.WriteLine(mediaName);

         }

    }

    However, it is too early to do that since I am still looking for a way to run the play/pause button.

    Any help will be much appreciated.

    Tuesday, January 8, 2008 10:42 AM

Answers

  • Hello, try to change this line:

    if (mPlayer.CurrentState == mPlayer.Play())

     

    To this:

    if (mPlayer.CurrentState == “Playing”)

     

    Also, I’ve seen that error message when you set a file’s Build Action to Page. You should instead set the Build Action to SilverlightPage.

     

    Thursday, January 10, 2008 2:03 AM

All replies

  • Hello, try to change this line:

    if (mPlayer.CurrentState == mPlayer.Play())

     

    To this:

    if (mPlayer.CurrentState == “Playing”)

     

    Also, I’ve seen that error message when you set a file’s Build Action to Page. You should instead set the Build Action to SilverlightPage.

     

    Thursday, January 10, 2008 2:03 AM
  • Hi  Yi-Lun Luo,

    Thank you for your replay. I was really struggling how to make it and it came out to be something very simple. :)

    So now I've encountered another problem.

    I am trying to build a control for playing my video on full screen. I've come up with the following solution:

    public void btnFullScreen(object sender, EventArgs e)
            {
                if (BrowserHost.IsFullScreen)
                {

                    // Here I set the full screen when the button for full screen is clicked
                    this.Height = BrowserHost.ActualHeight;
                    this.Width = BrowserHost.ActualWidth;
                    mPlayer.SetValue<double>(Canvas.LeftProperty, BrowserHost.ActualWidth);
                    mPlayer.SetValue<double>(Canvas.TopProperty, BrowserHost.ActualHeight);
                }
                else
                {

                    // Here I reverse back when esc key is clicked
                    this.Height = 656;
                    this.Width = 892;
                    mPlayer.SetValue<double>(Canvas.LeftProperty, BrowserHost.ActualWidth / 2);
                    mPlayer.SetValue<double>(Canvas.TopProperty, BrowserHost.ActualHeight / 2);
                }
            }

    The problem is that the movie freezes and just displays top right corner centered on the screen. I have to refresh the application in order to "unstuck".

    This worked fine for me for Canvas with TextBlock but doesn't work with the MediaElement
     
    I've included Interop library since it is needed for full screen handling. My media element is called mPlayer. Anybody has any idea?

    Wednesday, January 16, 2008 10:36 AM