コード例 #1
0
    void OnRenderObject()
    {
        if (mAppPaused)
        {
            return;
        }

        CheckIconPlaneVisibility();

        if (!mIsInited)
        {
            if (!mInitInProgess)
            {
                mInitInProgess = true;
                StartCoroutine(InitVideoPlayer());
            }

            return;
        }

        if (isPlayableOnTexture)
        {
            // Update the video texture with the latest video frame
            VideoPlayerHelper.MediaState state = mVideoPlayer.UpdateVideoData();
            if ((state == VideoPlayerHelper.MediaState.PLAYING) ||
                (state == VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN))
            {
#if UNITY_WSA_10_0 && !UNITY_EDITOR
                // For Direct3D video texture update, we need to be on the rendering thread
                GL.IssuePluginEvent(VideoPlayerHelper.GetNativeRenderEventFunc(), 0);
#else
                GL.InvalidateState();
#endif
            }

            // Check for playback state change
            if (state != mCurrentState)
            {
                HandleStateChange(state);
                mCurrentState = state;
            }
        }
        else
        {
            // Get the current status
            VideoPlayerHelper.MediaState state = mVideoPlayer.GetStatus();
            if ((state == VideoPlayerHelper.MediaState.PLAYING) ||
                (state == VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN))
            {
                GL.InvalidateState();
            }

            // Check for playback state change
            if (state != mCurrentState)
            {
                HandleStateChange(state);
                mCurrentState = state;
            }
        }
    }
コード例 #2
0
 // Start is called before the first frame update
 void Start()
 {
     m_StagePlay   = FindObjectOfType <StagePlay>();
     videoPlayerSc = FindObjectOfType <VideoPlayerHelper>();
     Button_2.SetActive(false);
     Button_3.SetActive(false);
 }
コード例 #3
0
    void Start()
    {
        // Find the icon plane (child of this object)
        mIconPlane = transform.Find("Icon").gameObject;

        // A filename or url must be set in the inspector
        if (m_path == null || m_path.Length == 0)
        {
            Debug.Log("Please set a video url in the Inspector");
            HandleStateChange(VideoPlayerHelper.MediaState.ERROR);
            mCurrentState = VideoPlayerHelper.MediaState.ERROR;
            this.enabled  = false;
        }
        else
        {
            // Set the current state to Not Ready
            HandleStateChange(VideoPlayerHelper.MediaState.NOT_READY);
            mCurrentState = VideoPlayerHelper.MediaState.NOT_READY;
        }
        // Create the video player and set the filename
        mVideoPlayer = new VideoPlayerHelper();
        mVideoPlayer.SetFilename(m_path);

        // Flip the plane as the video texture is mirrored on the horizontal
        transform.localScale = new Vector3(-1 * Mathf.Abs(transform.localScale.x),
                                           transform.localScale.y, transform.localScale.z);

        // Scale the icon
        ScaleIcon();
    }
コード例 #4
0
    void Start()
    {
        // Find the icon plane (child of this object)
        mIconPlane = transform.Find("Icon").gameObject;

        // A filename or url must be set in the inspector
        if (m_path == null || m_path.Length == 0)
        {
            Debug.Log("Please set a video url in the Inspector");
            HandleStateChange(VideoPlayerHelper.MediaState.ERROR);
            mCurrentState = VideoPlayerHelper.MediaState.ERROR;
            this.enabled  = false;
        }
        else
        {
            // Set the current state to Not Ready
            HandleStateChange(VideoPlayerHelper.MediaState.NOT_READY);
            mCurrentState = VideoPlayerHelper.MediaState.NOT_READY;
        }
        // Create the video player and set the filename
        mVideoPlayer = new VideoPlayerHelper();
        mVideoPlayer.SetFilename(m_path, sponsor, sponsorName, NumberOfFrame);

        // Flip the plane as the video texture is mirrored on the horizontal
        transform.localScale = new Vector3(-1 * Mathf.Abs(transform.localScale.x),
                                           transform.localScale.y, transform.localScale.z);

        /*
         * //******* // no affect de?
         * // Pass the video texture id to the video player
         *
         * mVideoPlayer.SetVideoTexturePtr(mVideoTexture.GetNativeTexturePtr());
         *
         * // Get the video width and height
         *
         * int videoWidth = mVideoPlayer.GetVideoWidth();
         *
         * int videoHeight = mVideoPlayer.GetVideoHeight();
         *
         * if (videoWidth > 3 && videoHeight > 3)
         *
         * {
         *
         *  // Scale the video plane to match the video aspect ratio
         *
         *  float aspect = videoWidth / (float)videoHeight;// / (float)videoWidth;
         *
         *  // Flip the plane as the video texture is mirrored on the horizontal <---This flips it
         *  transform.localScale = new Vector3(-0.0f, 0.1f, 0.1f * 0.1f*aspect);
         * }
         * //*******
         */

        // Scale the icon
        ScaleIcon();
    }
コード例 #5
0
    private void Update()
    {
        if (selected != null)
        {
            if (changeColor)
            {
                crosshair.color = defaultColor;
            }
            if (showImage)
            {
                crosshair.sprite = defaultImage;
            }

            popUpText.gameObject.SetActive(false);
            selected = null;
        }

        var        ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, aimRange))
        {
            var selection = hit.transform;
            var video     = selection.GetComponent <VideoPlayerHelper>();
            if (video == null)
            {
                return;
            }

            if (changeColor)
            {
                crosshair.color = newColor;
            }
            if (showImage)
            {
                crosshair.sprite = targetingImage;
            }

            popUpText.gameObject.SetActive(true);
            selected = video;
        }

        if (selected != null)
        {
            if (Input.GetMouseButtonDown(0))
            {
                selected.Play();
                DatabaseManager.currentUser.score += 10;
                DatabaseManager.instance.SaveData();
            }
        }
    }
コード例 #6
0
    // Start is called before the first frame update
    void Start()
    {
        // 添加监听
        inputField.onEndEdit.AddListener(TextFieldOnEndEdit);
        prepareBtn.onClick.AddListener(Prepare);
        playBtn.onClick.AddListener(Play);
        pauseBtn.onClick.AddListener(Pause);
        stopBtn.onClick.AddListener(Stop);
        clearBtn.onClick.AddListener(ClearLog);

        progressSlider.minValue = 0.0f;
        progressSlider.value    = 0.0f;
        progressSlider.GetComponent <SliderDrag>().EndDrag = progressSliderValueDidChange;


        volumeSlider.minValue = 0.0f;
        volumeSlider.maxValue = 1.0f;
        volumeSlider.value    = 1.0f;
        volumeSlider.GetComponent <SliderDrag>().EndDrag = volumeSliderValueDidChange;


        float width  = displayLayer.rectTransform.rect.width;
        float height = displayLayer.rectTransform.rect.height;

        mVideoTexture            = new Texture2D((int)width, (int)height, TextureFormat.RGB565, false);
        mVideoTexture.filterMode = FilterMode.Bilinear;
        mVideoTexture.wrapMode   = TextureWrapMode.Clamp;

        displayLayer.texture = mVideoTexture;

        //// 初始化播放器
        mVideoPlayer = gameObject.AddComponent <VideoPlayerHelper>();
        mVideoPlayer.Init();

        // 注意纹理的获取时机,mVideoTexture被负载到gameobject才能获取到texturePtr
        texPtr = mVideoTexture.GetNativeTexturePtr();
        mVideoPlayer.SetVideoTexturePtr(texPtr);


        HandleStateChange(VideoPlayerHelper.MediaState.NOT_READY);
        mCurrentState = VideoPlayerHelper.MediaState.NOT_READY;
    }
コード例 #7
0
        internal void PlayVideo()
        {
            if (this._inPlayRequest || (DateTime.Now - this._lastTimeCompletedPlayRequest).TotalSeconds < 3.5)
            {
                return;
            }
            this._inPlayRequest = true;
            int selectedResolution = this.GetSelectedResolution();

            base.SetInProgress(true, CommonResources.Loading);
            VideoPlayerHelper.PlayVideo(this.Video, delegate
            {
                Execute.ExecuteOnUIThread(delegate
                {
                    base.SetInProgress(false, "");
                    this._inPlayRequest = false;
                    this._lastTimeCompletedPlayRequest = DateTime.Now;
                });
            }, selectedResolution, this._actionSource, this._videoContext);
        }
コード例 #8
0
        /// <summary>
        ///播放路径下的视频;
        /// </summary>
        /// <param name="_videoimage">播放视频到指定rawimage.</param>
        /// <param name="_videopath">视频名称.</param>
        /// <param name="_isloop">视频是否循环.</param>
        private void PlayVideo(Notification _notif)
        {
            VideoPlayerHelper tmp_videoPlayerHelper = _notif.param as VideoPlayerHelper;
            VideoPlayer       m_Vp = tmp_videoPlayerHelper.m_Videorender.GetComponent <VideoPlayer>();

            if (m_Vp != null)
            {
                if (m_Vp.isPlaying)
                {
                    m_Vp.Stop();
                }
            }
            else
            {
                m_Vp = tmp_videoPlayerHelper.m_Videorender.AddComponent <VideoPlayer>();
            }
            m_Vp.source                 = VideoSource.Url;
            m_Vp.url                    = "file:///" + Config.DirToDownload + "/Download/Video/" + tmp_videoPlayerHelper.m_Videoname + ".mp4";
            m_Vp.renderMode             = VideoRenderMode.MaterialOverride;
            m_Vp.targetMaterialRenderer = tmp_videoPlayerHelper.m_Videorender.GetComponent <Renderer>();
            tmp_videoPlayerHelper.m_Videorender.GetComponent <Renderer>().material.shader = Shader.Find("Custom/Video360");
            m_Vp.Play();
            m_Vp.isLooping = tmp_videoPlayerHelper.m_Isloop;
        }
コード例 #9
0
    void Start()
    {
        // Find the icon plane (child of this object)
        mIconPlane = transform.Find("Icon").gameObject;

        // A filename or url must be set in the inspector
        if (m_path == null || m_path.Length == 0)
        {
            Debug.Log("Please set a video url in the Inspector");
            HandleStateChange(VideoPlayerHelper.MediaState.ERROR);
            mCurrentState = VideoPlayerHelper.MediaState.ERROR;
            this.enabled = false;
        }
        else
        {
            // Set the current state to Not Ready
            HandleStateChange(VideoPlayerHelper.MediaState.NOT_READY);
            mCurrentState = VideoPlayerHelper.MediaState.NOT_READY;
        }
        // Create the video player and set the filename
        mVideoPlayer = new VideoPlayerHelper();
        mVideoPlayer.SetFilename(m_path);

        // Flip the plane as the video texture is mirrored on the horizontal
        transform.localScale = new Vector3(-1 * Mathf.Abs(transform.localScale.x),
                transform.localScale.y, transform.localScale.z);

        // Scale the icon
        ScaleIcon();
    }
コード例 #10
0
    // Handle video playback state changes
    private void HandleStateChange(VideoPlayerHelper.MediaState newState)
    {
        // If the movie is playing or paused render the video texture
        // Otherwise render the keyframe
        if (newState == VideoPlayerHelper.MediaState.PLAYING ||
            newState == VideoPlayerHelper.MediaState.PAUSED)
        {
            Material mat = GetComponent<Renderer>().material;
            mat.mainTexture = mVideoTexture;
            mat.mainTextureScale = new Vector2(1, 1);
        }
        else
        {
            if (mKeyframeTexture != null)
            {
                Material mat = GetComponent<Renderer>().material;
                mat.mainTexture = mKeyframeTexture;
                mat.mainTextureScale = new Vector2(1, -1);
            }
        }

        // Display the appropriate icon, or disable if not needed
        switch (newState)
        {
            case VideoPlayerHelper.MediaState.READY:
            case VideoPlayerHelper.MediaState.REACHED_END:
            case VideoPlayerHelper.MediaState.PAUSED:
            case VideoPlayerHelper.MediaState.STOPPED:
                mIconPlane.GetComponent<Renderer>().material.mainTexture = m_playTexture;
                mIconPlaneActive = true;
                break;

            case VideoPlayerHelper.MediaState.NOT_READY:
            case VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN:
                mIconPlane.GetComponent<Renderer>().material.mainTexture = m_busyTexture;
                mIconPlaneActive = true;
                break;

            case VideoPlayerHelper.MediaState.ERROR:
                mIconPlane.GetComponent<Renderer>().material.mainTexture = m_errorTexture;
                mIconPlaneActive = true;
                break;

            default:
                mIconPlaneActive = false;
                break;
        }

        if (newState == VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN)
        {
            // Switching to full screen, disable QCARBehaviour (only applicable for iOS)
            QCARBehaviour qcarBehaviour = (QCARBehaviour) FindObjectOfType(typeof(QCARBehaviour));
            qcarBehaviour.enabled = false;
        }
        else if (mCurrentState == VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN)
        {
            // Switching away from full screen, enable QCARBehaviour (only applicable for iOS)
            QCARBehaviour qcarBehaviour = (QCARBehaviour) FindObjectOfType(typeof(QCARBehaviour));
            qcarBehaviour.enabled = true;

            StartCoroutine ( ResetToPortraitSmoothly() );
        }
    }