示例#1
0
 public override void stopDecoding()
 {
     if (decoderState >= DecoderNative.DecoderState.INITIALIZING)
     {
         print(LOG_TAG + " stop decoding.");
         decoderState = DecoderNative.DecoderState.STOP;
         releaseTextures();
         if (isAudioEnabled)
         {
             StopCoroutine("audioPlay");
             backgroundWorker.CancelAsync();
             if (audioSource != null)
             {
                 for (var i = 0; i < SWAP_BUFFER_NUM; i++)
                 {
                     if (audioSource[i] != null)
                     {
                         Destroy(audioSource[i].clip);
                         Destroy(audioSource[i]);
                         audioSource[i] = null;
                     }
                 }
             }
         }
         DecoderNative.nativeDestroyDecoder(decoderID);
         decoderID            = -1;
         decoderState         = DecoderNative.DecoderState.NOT_INITIALIZED;
         isVideoEnabled       = isAudioEnabled = false;
         isVideoReadyToReplay = isAudioReadyToReplay = false;
         isAllAudioChEnabled  = false;
     }
 }
        public static void loadVideoThumb(GameObject obj, string filePath, float time)
        {
            if (!File.Exists(filePath))
            {
                print(LOG_TAG + " File not found!");
                return;
            }

            var decID     = -1;
            var width     = 0;
            var height    = 0;
            var totalTime = 0.0f;

            DecoderNative.nativeCreateDecoder(filePath, ref decID);
            DecoderNative.nativeGetVideoFormat(decID, ref width, ref height, ref totalTime);
            if (!DecoderNative.nativeStartDecoding(decID))
            {
                print(LOG_TAG + " Decoding not start.");
                return;
            }

            var thumbY   = new Texture2D(width, height, TextureFormat.Alpha8, false);
            var thumbU   = new Texture2D(width / 2, height / 2, TextureFormat.Alpha8, false);
            var thumbV   = new Texture2D(width / 2, height / 2, TextureFormat.Alpha8, false);
            var thumbMat = obj.GetComponent <MeshRenderer>().material;

            if (thumbMat == null)
            {
                print(LOG_TAG + " Target has no MeshRenderer.");
                DecoderNative.nativeDestroyDecoder(decID);
                return;
            }

            thumbMat.SetTexture("_YTex", thumbY);
            thumbMat.SetTexture("_UTex", thumbU);
            thumbMat.SetTexture("_VTex", thumbV);

            DecoderNative.nativeLoadThumbnail(decID, time, thumbY.GetNativeTexturePtr(), thumbU.GetNativeTexturePtr(),
                                              thumbV.GetNativeTexturePtr());
            DecoderNative.nativeDestroyDecoder(decID);
        }