AVPro makes video thumbnails in batches

A recent project has a need to make video thumbnails when the video is not sure. The general idea is to get all video paths, load them into the player according to the path, and load video thumbnails one by one according to the player. , not much nonsense look at the code

  public RawImage raw;
    public List<Texture2D> thumbnail = new List<Texture2D>();//存放缩略图列表
    int i = 0;//计算视频长度
    //在视频未播放前 把所有的视频缩略图都加载出来
    IEnumerator IESaveVideoThumb(MediaPlayer mediaPlayer)//缩略图
    {
    
         
        yield return null;                                                                      //视频路径
        mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder, VideoManager._instance.videoNameList[i], false);
        i++;
        //  mediaPlayer.Info.GetDurationMs() 取的是毫秒
        //这个地方不加延迟的话就获取不到他的帧数
        yield return new  WaitForSeconds(0.12f);
        float durationMs = mediaPlayer.Info.GetDurationMs()/1000;
        float ms = durationMs < 1 ? durationMs : 1;
        //取视频中1秒位置保存为图片
        Texture2D t = mediaPlayer.ExtractFrame(null, ms);
        thumbnail.Add(t);
        raw.texture = t;
        if (i< VideoManager._instance.videoNameList.Count)
        {
    
    
            StartCoroutine(IESaveVideoThumb(mediaPlayer)) ;
        }
        else
        {
    
    
         //当所有缩略图制作完成执行...
        }

    }

Guess you like

Origin blog.csdn.net/qq_43687127/article/details/115758039