Load video at startup

Sep 1, 2010 at 7:54 AM

Hi,

I try to load a video at application startup, but the video doesn't play.

This is my code :

	smfPlayer.Playlist.Clear();

                PlaylistItem pList = new PlaylistItem();
                pList.MediaSource = new Uri(video, UriKind.Absolute);
                smfPlayer.Playlist.Add(pList);
                smfPlayer.CurrentPlaylistItem = pList;
                smfPlayer.Play();
When I relauch this code with a button click, the video is launched.
 
Why can't I lauch the video directly?
Regards.

Sep 1, 2010 at 2:21 PM

you could try gotoplaylistitem(pList)...  then call play... might sound stupid but you can try and let us know.  Worked for me...

Cheers;

Brendon

Sep 2, 2010 at 8:31 AM

Thanks for your answer.

I try to use GotoplaylistItem but it doesn't work for me.

My code was in the constructor and I put it in the Loaded event, but it doesn't changed anything.

 

I've found a solution, but it's a little hazardous. I make a Sleep with a BackgroundWorker before loading my file in the playlist.

But, this solution works, so...

Code :

	void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (tmpVideo != "")
            {
                tbfileName.Text = tmpVideo;

                BackgroundWorker bgw = new BackgroundWorker();
                bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
                bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
                bgw.RunWorkerAsync();
            }
        }

        void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            System.Threading.Thread.Sleep(10);
        }

        void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            
	smfPlayer.Playlist.Clear();

                PlaylistItem pList = new PlaylistItem();
                pList.MediaSource = new Uri(tbfileName.Text, UriKind.Absolute);
                smfPlayer.Playlist.Add(pList);
                smfPlayer.CurrentPlaylistItem = pList;

                smfPlayer.Play();
}