Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is my first question here...
I hope someone will be able to help me....
I have a form which has two panels.. one panel is for video player and other one is for ticker(label which moves from right to left)...
Problem is that this ticker moves fine when the video is playing.. but it pauses when the video is completed and new video is loaded... I am using windows media player.. And both video and the ticker is playing on a different thread...
Here's my piece of code..

C#
private void Form_Load(object sender, EventArgs e)
    {
          
        System.Threading.ThreadStart starter = delegate
        {
          videoplayer();
        };
        new System.Threading.Thread(starter).Start();
          

        System.Threading.ThreadStart SecondThread = delegate
        {
            tickerplayer();
        };
        new System.Threading.Thread(SecondThread).Start();
    }

here's my code for ticker
C#
private void tickerplayer()
{
    tckr.Font = new Font("Arial", 10, FontStyle.Bold);
    tckr.BackColor = Color.Transparent;
    tckr.ForeColor = Color.Black;
    tckr.Parent.BackColor = Color.Gray;
    tckr.Text = "Denzel Washington";
    tckr.TextAlign = ContentAlignment.MiddleCenter;
    System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
    t.Interval = 1;
    t.Start();
    t.Tick += (sender, EventArgs) =>
    {
        int z, hgt;
        hgt = tckr.Location.Y;
        z = tckr.Location.X;

        if (z <= 0 - tckr.Width)
            z = tckr.Parent.Width - 0;
        else
            z = tckr.Location.X - 3;

        tckr.Location = new Point(z, hgt);

    };
}

and this is for video
C#
void wp2_PlayStateChange(object sender, _WMPOCXEvents_PlayStateChangeEvent e)
{
    if (wp2.playState == WMPPlayState.wmppsPlaying)
    {
        if (play == true)
        {
            media = wp1.newMedia(@"D:\Parafait Home\Signage\ctvc_JOE.avi");
            play = false;
            wp1.currentMedia = media;
            wp1.Ctlcontrols.stop();
        }
    }
    if (wp2.playState == WMPPlayState.wmppsMediaEnded)
    {
        wp2.currentPlaylist.clear();
        play = true;
        wp1.Ctlcontrols.play();
    }
    return;
}

void wp1_PlayStateChange(object sender, _WMPOCXEvents_PlayStateChangeEvent e)
{
    if (wp1.playState == WMPPlayState.wmppsPlaying)
    {
        if (play == true)
        {
            media = wp2.newMedia(@"D:\Parafait Home\Signage\ctvc_BAYER.AVI");
            play = false;
            wp2.currentMedia = media;
            wp2.Ctlcontrols.stop();
        }
    }
    if (wp1.playState == WMPPlayState.wmppsMediaEnded)
    {
        wp1.currentPlaylist.clear();
        play = true;
        wp2.Ctlcontrols.play();
    }
    return;
}

private void videoplayer()
{
    media = wp1.newMedia(@"D:\Parafait Home\Signage\ctvc_JOE.avi");
    play = true;
    wp1.currentMedia = media;
}
Posted
Updated 12-Sep-13 1:43am
v2

1 solution

Firstly, welcome!

I'm suprised you aren't getting any exceptions thrown as you are breaking the cardinal rule in GUI programming that only the thread which creates a control can update it.

First of all, don't call tickerplayer on a background thead. Call that on the main thread and see what happens. All it does is set up a timer and those calls to set the ForeColor/BackColor should not be done on a background thread

The timer takes care of the 'asynchronous' aspects of updating the ticker - this should be used on the main thread.

Also, when you paste code try and put it in a code block (formatting) or people will get huffy. It's an odd place this...

Edit - I don't think you should be explicitly creating threads at all. The Timer will do your ticker, the video player should take care of itself.
 
Share this answer
 
v2
Comments
Sachin Athrady 12-Sep-13 7:47am    
Sir.. this is my new approach... Calling each player as separate ui thread.. but it still doesnt do it for me... same problem.. here each player is in form1(video) and form2(ticker) respectively.. code is same..

namespace replicaThread
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();

Thread thread1 = new Thread(() =>
{
Form2 f2 = new Form2();
Application.Run(f2);
});
thread1.ApartmentState = ApartmentState.STA;
thread1.Start();


Thread thread = new Thread(() =>
{
Form1 f1 = new Form1();
Application.Run(f1);
});
thread.ApartmentState = ApartmentState.STA;
thread.Start();
}
}
}
Rob Philpott 12-Sep-13 8:14am    
Interesting that. So now you have two main windows, fully independent and you are still getting this issue? Again it's an odd way you are doing it. Rather than do that in the constructor of Form3, do it in the Main() function. Even so though I think you've got sufficient isolation that they shouldn't interfere with each other. Have a look in task manager and see how busy you computer gets when swapping videos.
Sachin Athrady 12-Sep-13 8:23am    
yea.. Exactly i played only ticker this time... commented whole video thread.. now only ticker is playing... and now i open up a video in windows media player outside the application.. Same problem still exists.. Now this is hard bro....
Rob Philpott 12-Sep-13 12:34pm    
Yes. Good luck - I don't see how you can fix that.
Sachin Athrady 12-Sep-13 7:48am    
as i am new to this.. i dont knw how to ident my code here..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900