简体   繁体   中英

How to implement Event handler interface in C#?

I have an interface called IVideoPreparedListener that looks like this:

public interface IVideoPreparedListener
{
    void onVideoPrepared(Video video);
}

I have an even listener method in another class that looks like this:

public void setOnVideoPreparedListener(IVideoPreparedListener iVideoPreparedListener)
    {
        this.iVideoPreparedListener = iVideoPreparedListener;
    }

I'm trying to invoke this method by doing:

 videoPlayer2.setOnVideoPreparedListener(?)

The class which I'm invoking this method in, implements the event handler interface. I'm not sure what parameter should be passed inside the setOnVideoPreparedListener method so the interface method onVideoPrepared is invoked. Normally in java I would do something like this:

ideoPlayer2.setOnVideoPreparedListener(new IVideoPreparedListener() {
                @Override
                public void onVideoPrepared(Video mVideo) {

                    //Pause current playing video if any
                    if(video.getIndexPosition() == mVideo.getIndexPosition())
                    {
                        if(currentPlayingVideo!=null)
                        {
                            VideoPlayer videoPlayer1 = videos.get(currentPlayingVideo.getIndexPosition());
                            videoPlayer1.pausePlay();
                        }
                        videoPlayer2.mp.start();
                        currentPlayingVideo = mVideo;
                    }


                }
            });

Any idea how I can do something similar with C#?

You said the class that you're in implements the event handler interface. If so, then just call ideoPlayer2.setOnVideoPreparedListener(this); .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM