Usage of unity avprovider plug-in

Time:2022-5-6

1. Create a new mediaplayer component

这里写图片描述

2. Create a new avprovideo component under canvas

And assign the mediaplayer component created in the previous step to the mediaplayer on the avprovider component

这里写图片描述

这里写图片描述

3. Put the video to be played in the streamingassets folder

The next step is to call with code

1、_ mediaPlayer. Openvideofromfile (mediaplayer. Filelocation. Relativetostreamingassetsfolder, video path, whether to play automatically)// Load video

2、_ mediaPlayer. Control. Play();// Play video

3、_ mediaPlayer. Control. Muteaudio (mute or not)// Mute

4、_ mediaPlayer. Control. Pause();// Pause video

5、_ mediaPlayer. Control. Seek (Progress)// progress bar

6、_ mediaPlayer. Control. SetVolume// set volume

7、_ mediaPlayer. Control. Rewind();// to replay

8、

这里写图片描述

Supplement: unity avprovideo can automatically load the next video after the current video is played

Avprovideo is a video playback plug-in used by unity3d. It can not only realize the basic playback function, but also realize the drag and drop of progress bar and rate adjustment, play 4K video, 360 degree panoramic video, etc., and optimize different platforms.

The following script can complete the current video playback and automatically load and play the next video

/** 
 *Copyright(C) 2017 by MMHD 
 *All rights reserved. 
 *FileName:     AVProManager.cs
 *Author:       Joel
 *Date:         2018.2.2 
 *Description: avprovideo automatically plays the next video after the current video is played
 *History: By307035570
*/
using RenderHeads.Media.AVProVideo;
using System.Collections;
using System.Collections.Generic;
using UnityEngine; 
public class AVProManager : MonoBehaviour { 
    public void OnVideoEvent(MediaPlayer mp, MediaPlayerEvent.EventType et, ErrorCode er)
    {
        switch (et)
        {
            case MediaPlayerEvent.EventType.ReadyToPlay:
                Debug.Log("ReadyToPlay");
                break;
            case MediaPlayerEvent.EventType.FirstFrameReady:
                Debug.Log("First frame ready");
                break;
            case MediaPlayerEvent.EventType.FinishedPlaying:
                {
                    transform.GetComponent<MediaPlayer>().m_VideoPath = "StreamingAssets/Video/video.mp4";
                    MediaPlayer media = (transform.GetComponent<MediaPlayer>()) as MediaPlayer;
                    media.OpenVideoFromFile(media.m_VideoLocation, media.m_VideoPath, media.m_AutoStart);
                }
                break;
            default:
                break;
        }
    }
}

The above is my personal experience. I hope I can give you a reference, and I hope you can support developpaer. If there are mistakes or not fully considered, please don’t hesitate to comment.

Recommended Today

Resolve the mapping problem between oid and relfilenode in PostgreSQL

Author Li ChuanchengCertified Expert of China PG branch, senior kernel R & D Engineer of Hangao software https://zhuanlan.zhihu.com/p/342466054 The table in PostgreSQL will have a relfilenode value to specify the file name of the table on the disk (except for external tables and partition tables). In general, in PG_ This value can be found in […]