Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to call StartActivity in OnVideoEnded()

rajveerrajveer USMember ✭✭

Hi Everyone, I want to call StartActivity in OnVideoEnded().please help to solve this.
Thank you.

`class MyPlayerStateChangeListener : Java.Lang.Object, IYouTubePlayerPlayerStateChangeListener
{

    public static string PlayerState = "UNINITIALIZED";


    #region IYouTubePlayerPlayerStateChangeListener implementation

    public void OnAdStarted()
    {
        PlayerState = "AD_STARTED";
    }

    public void OnError(YouTubePlayerErrorReason p0)
    {
        PlayerState = "ERROR (" + p0 + ")";
        if (p0 == YouTubePlayerErrorReason.UnexpectedServiceDisconnection)
        {

        }
    }

    public void OnLoaded(string p0)
    {
        PlayerState = String.Format("VIDEO LOADED");
    }

    public void OnLoading()
    {
        PlayerState = "LOADING";
    }


    public void OnVideoEnded()
    {
        PlayerState = "VIDEO_ENDED";
    }

    public void OnVideoStarted()
    {
        PlayerState = "VIDEO_STARTED";
    }

`

Posts

  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭✭

    Hello @rajveer

    not sure to understand the question, but for to load an activity just do this
    `
    StartActivity(typeof(ACTIVITYNAME);

    `

    i think but never use => IYouTubePlayerPlayerStateChangeListener when the video is ended the method corresponding will be call ...
    just add a start activity must be solve your problem ...

    hope this help

  • rajveerrajveer USMember ✭✭

    Hi @ChristopheBERNARD ,thanks for your responce. I've tried StartActivity(typeof(ACTIVITYNAME); but it shows "The name StartActivity does not exist in the current context".

  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭✭

    Ok, sorry i didn't see that you are not in a activity you are in your own class

    try something like this

    `
    class MyPlayerStateChangeListener

    private Context theContext;

    //constructor and i pass the context of your activity who start the youtube API
    public MyPlayerStateChangeListener (Context ctx)
    {
    theContext = ctx;
    }

    .....
    theContext.StartActitivy(typeof(activityname);

    `

    normally it will be work
    tell me ... i work until 4 pm :)

  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭✭

    also don't forget to modify the call to your class => MyPlayerStateChangeListener(this); in your activity

  • rajveerrajveer USMember ✭✭

    Thankyou @ChristopheBERNARD , it works fine :smile:

  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭✭

    Hello @rajveer

    great to read that ...i'm not an expert but i try to give some help when i can ...

    have a nice day

Sign In or Register to comment.