'VideoPlayer' does not contain a definition for 'Play' and no accessible extension method 'Play'

Hi, I ran into an issue about a week ago. When I opened Unity, it said that there were issues with my script and that I should open Unity in safe mode. This was odd because there were no issues when I left Unity, like they had been created in between closing Unity and Opening it again. I opened it in safe mode, and found that the issue was that all of the functions to do with the video player component (stop, clip, play) weren’t registering, and they have a red line under them in visual studio. These functions were fine before but suddenly weren’t working.
I tried updating Unity which solved the issue once, but after closing and opening it again, the same issue occurred. My visual studio is updated to the latest version.
Any ideas? I don’t think it’s an issue with my code, but an issue with how visual studio or unity is reading my code (but obviously I could be wrong.)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
public class VideoPlaying : MonoBehaviour
{
    private VideoPlayer videoPlayer;
    public VideoClip[] videoClips;
    static VideoSelector videoSelectorScript;
    //0 = Blue, 1 = Red, 2 = Party, 3 = Purple, 4 = Orange
    int valueOfParty;
    int personTalking;
    Vector3 startPosition;
    Vector3 startScale;
    private void Awake()
    {
        videoPlayer = GetComponent<VideoPlayer>();
        videoSelectorScript = GetComponentInParent<VideoSelector>();
    }
    void Start()
    {
        startPosition = transform.localPosition;
        startScale = transform.localScale;
        switch (gameObject.name)
        {
            case "VideoPlayerBlue":
                valueOfParty = 0;
                break;
            case "VideoPlayerRed":
                valueOfParty = 1;
                break;
            case "VideoPlayerParty":
                valueOfParty = 2;
                break;
            case "VideoPlayerPurple":
                valueOfParty = 3;
                break;
            case "VideoPlayerOrange":
                valueOfParty = 4;
                break;
        }
    }
    //Every time a prompt is accepted, each of these ints is used to determine the video to play
    //and the transform of the object
    //Party recieving is the literally just which party has this class attached to it
    //firstpersonspeaking and secondpersonspeaking starts at one and ends at 5, with 0 representing nothing.
    public void ClipUpdate(int numberOfPeopleSpeaking, int firstPersonSpeaking, int secondPersonSpeaking, int firstClipNumber, int secondClipNumber)
    {
        switch (numberOfPeopleSpeaking)
        {
            case 0:
                //Stationary
                gameObject.SetActive(true);
                transform.localPosition = startPosition;
                transform.localScale = startScale;
                videoPlayer.clip = videoClips[0];
                videoPlayer.Play();
                break;
            case 1:
                //If you are the one talking
                if (firstPersonSpeaking == valueOfParty + 1)
                {
                    gameObject.SetActive(true);
                    videoPlayer.clip = videoClips[firstClipNumber];
                    videoPlayer.Play();
                    transform.localPosition = Vector3.zero;
                    transform.localScale = new Vector3(8, 6, 1);
                    Invoke("VideoOver", (float)videoClips[firstClipNumber].length);
                }
                else
                {
                    videoPlayer.Stop();
                    gameObject.SetActive(false);
                }
                break;
            case 2:
                if (firstPersonSpeaking == valueOfParty + 1)
                {
                    transform.localPosition = new Vector3(-2.75f, 0, 0);
                    transform.localScale = new Vector3(5.4f, 4.05f, 1);
                    videoPlayer.clip = videoClips[firstClipNumber];
                    videoPlayer.Play();
                    gameObject.SetActive(true);
                }
                else if (secondPersonSpeaking == valueOfParty + 1)
                {
                    transform.localPosition = new Vector3(2.75f, 0, 0);
                    transform.localScale = new Vector3(5.4f, 4.05f, 1);
                    videoPlayer.clip = videoClips[secondClipNumber];
                    videoPlayer.Play();
                    gameObject.SetActive(true);
                    Invoke("VideoOver", (float)videoClips[secondClipNumber].length);
                }
                else
                {
                    videoPlayer.Stop();
                    gameObject.SetActive(false);
                }
                break;
            default:
                break;
        }
      
      
      
    }
    void VideoOver()
    {
        videoSelectorScript.ContactPlayingScript(0, 0, 0, 0, 0);
        videoSelectorScript.Invoke("VideoEnd", 0.5f);
    }
}

Sorry for the long script. The important thing is that videoPlayer.Stop, videoPlayer.Play and videoPlayer.clip are all underlined in red.

Actually, I should note that only the “stop,” “play,” and “clip” parts are underlined. videoPlayer isn’t underlined in red.

There is no Play method on line 75 as mentioned in one of the errors, for example. All the other errors don’t match either. Do you have duplicate scripts in your project?

I really appreciate that you replied. I am aware that the issue is that it says there is no play method, but I’m wondering why, because it was working before. I’m following this tutorial series:
https://www.youtube.com/watch?v=zGzdFrZRNG8
in case you’re wondering.

There are several VideoPlaying scripts in the scene, yeah. (VideoPlaying is the script I pasted above, the only one with issues and the only one with video player methods.)

Just letting you know, I’m pretty sure that this isn’t an issue with the code specifically. It’s like unity completely forgot about the in built methods of the VideoPlayer component.

I should also note that when this issue first started popping up, I updated my unity version to the newest version. When I opened it then, all of the scripts worked. The next time I opened Unity, the same issue with the video player methods came back. This is a big part of the reason that I don’t think this problem came about because of the script itself.

Again, thanks for replying.

That’s not what JeffDUnity was saying. In the script you provided, the errors in your screenshot do not match the lines where the clip, Play, or Stop calls are being made. For example, your error says that on line 75 there is a call to the Play method (which it can’t find in VideoPlayer class) but your script does not have a call to Play on line 75 (it is just the break; line. Have you changed the script prior to pasting it here?

Are you absolutely sure that you do not have two VideoPlaying scripts in your project (in which case it might not be the script that you are pasting, but another one named the same located somewhere else in your project)?

Thanks for the reply. All of the error lines stated in the editor are actually correct, sorry for the misunderstanding. When I pasted my code into the forum it deleted a bunch of empty lines in the code, presumably to make it look more compact or something. There are 4 Video playing scripts in the scene, but since it opens in safe mode I assume that this isn’t the issue or anything. If you mean “duplicate” as in multiple of the same script in the files, I’ve checked and there isn’t.

Is there any way to go into the code with all of the default VideoPlayer methods? That might give an explanation as to why the methods aren’t working. It feels like all of the code associated with VideoPlayer has just been deleted. Perhaps I accidentally deleted those scripts somehow?

Please show your exact code that matches with the errors listed.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;

public class VideoPlaying : MonoBehaviour
{
    private VideoPlayer videoPlayer;
    public VideoClip[] videoClips;

    static VideoSelector videoSelectorScript;

    //0 = Blue, 1 = Red, 2 = Party, 3 = Purple, 4 = Orange
    int valueOfParty;

    int personTalking;

    Vector3 startPosition;
    Vector3 startScale;

    private void Awake()
    {
        videoPlayer = GetComponent<VideoPlayer>();
        videoSelectorScript = GetComponentInParent<VideoSelector>();
    }

    void Start()
    {
        startPosition = transform.localPosition;
        startScale = transform.localScale;

        switch (gameObject.name)
        {
            case "VideoPlayerBlue":
                valueOfParty = 0;
                break;
            case "VideoPlayerRed":
                valueOfParty = 1;
                break;
            case "VideoPlayerParty":
                valueOfParty = 2;
                break;
            case "VideoPlayerPurple":
                valueOfParty = 3;
                break;
            case "VideoPlayerOrange":
                valueOfParty = 4;
                break;
        }
    }

    //Every time a prompt is accepted, each of these ints is used to determine the video to play
    //and the transform of the object
    //Party recieving is the literally just which party has this class attached to it
    //firstpersonspeaking and secondpersonspeaking starts at one and ends at 5, with 0 representing nothing.
    public void ClipUpdate(int numberOfPeopleSpeaking, int firstPersonSpeaking, int secondPersonSpeaking, int firstClipNumber, int secondClipNumber)
    {
        switch (numberOfPeopleSpeaking)
        {
            case 0:
                //Stationary
                gameObject.SetActive(true);
                transform.localPosition = startPosition;
                transform.localScale = startScale;
                videoPlayer.clip = videoClips[0];
                videoPlayer.Play();
                break;
            case 1:
                //If you are the one talking
                if (firstPersonSpeaking == valueOfParty + 1)
                {

                    gameObject.SetActive(true);
                    videoPlayer.clip = videoClips[firstClipNumber];
                    videoPlayer.Play();
                    transform.localPosition = Vector3.zero;
                    transform.localScale = new Vector3(8, 6, 1);

                    Invoke("VideoOver", (float)videoClips[firstClipNumber].length);
                }
                else
                {
                    videoPlayer.Stop();
                    gameObject.SetActive(false);
                }
                break;
            case 2:
                if (firstPersonSpeaking == valueOfParty + 1)
                {
                    transform.localPosition = new Vector3(-2.75f, 0, 0);
                    transform.localScale = new Vector3(5.4f, 4.05f, 1);
                    videoPlayer.clip = videoClips[firstClipNumber];
                    videoPlayer.Play();
                    gameObject.SetActive(true);
                }
                else if (secondPersonSpeaking == valueOfParty + 1)
                {
                    transform.localPosition = new Vector3(2.75f, 0, 0);
                    transform.localScale = new Vector3(5.4f, 4.05f, 1);
                    videoPlayer.clip = videoClips[secondClipNumber];
                    videoPlayer.Play();
                    gameObject.SetActive(true);

                    Invoke("VideoOver", (float)videoClips[secondClipNumber].length);
                }
                else
                {
                    videoPlayer.Stop();
                    gameObject.SetActive(false);
                }
                break;
            default:
                break;
        }
       
       
       
    }

    void VideoOver()
    {
        videoSelectorScript.ContactPlayingScript(0, 0, 0, 0, 0);
        videoSelectorScript.Invoke("VideoEnd", 0.5f);
    }

    //2.75, 5.4, 4.05

    // Update is called once per frame
    void Update()
    {
    }
}

This is the code, copied straight from the original and unedited.

@noodlefly45 Thank you for the updated code, it allows us to rule out some things. One question, does this code still run in the Editor, or do you get the message “All Compiler errors must be fixed first”? If it does run, then it’s only in Visual Studio where you are seeing these errors? As another test, create a new empty project, and attempt to call videoPlayer.Play similarly, let’s see if it’s only this project that is affected.

I bet you created a class named “VideoPlayer” and the C# compiler is picking that up instead of the one in the engine.

@Tautvydas-Zilys dude this was literally it I feel so dumb rn. No idea when or why I made a script called VideoPlayer with one line of useless code but there you go. Thanks heaps and thanks @JeffDUnity3D as well this is a school project so I appreciate the quick help :). idk why that emoji looks so bad but you get the idea