Question

AxWindowsMediaPlayer can be used for showing images to user. If you set URL to example.png, image will be shown to user for exactly 5seconds (read from Ctlcontrols.currentPosition value).

Although image will be shown to user for 5seconds, value of "currentMedia.duration" equals to 0. Moreover you cannot set duration using setItemInfo to value you would like to.

Is there any way how to show image to user using AxWindowsMediaPlayer for eg. 37.5seconds? Is there any easy way how to change that interval for different images, or is it somewhere hard-coded constant?

I am sure that much better solution would be to use different components (eg. pictureBox and timer) but I am looking for solution using AxWindowsMediaPlayer. And I am sure that desired behavior could be done by changing current position for demanded period of time :-) - but I would like to avoid this.

Prereq: WinForms, .NET 4.0, WMP 12 for Windows 7

Thanks a lot

Was it helpful?

Solution

In PlayStateChange event handler detect 'newState == 3` (Playing).

After this, call wmp.Ctlcontrols.pause() and start timer. On timer.Tick event release paused media item.

To release pause call wmp.Ctlcontrols.play(), but be carrefull. This will trigger "newState == 3" again.

Also, timer interval should be substracted for 5 seconds, and you can't set slide to less than 5 seconds.

Sample bellow is not tested, but I implement something like this:

    private System.Windows.Forms.Timer timer;

    private void OnPlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
    {
        switch (e.newState)
        {
            case 3:
                if (!timer.Enabled)
                {
                    this.player.Ctlcontrols.pause();
                    this.timer.Interval = (37 - 5) * 1000; // 37 seconds 
                    this.timer.Start();
                }
                break;
        }
    }

    protected override void OnTimerTick(object sender, EventArgs e)
    {
        this.player.Ctlcontrols.play();
        this.timer.Stop();
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top