예제 #1
0
        /**
         * 视频压缩
         */
        public void VideoCompress(string json)
        {
            Log.I("VideoCompress: " + json);
            VideoCompressModel model = SerializeHelper.FromJson <VideoCompressModel>(json);

            if (model != null)
            {
                SimpleEventSystem.Publish(new VideoCompressResult(model));
            }
        }
예제 #2
0
        protected override void OnInit(QFramework.IUIData uiData)
        {
            mData             = uiData as AttendanceAddPanelData ?? new AttendanceAddPanelData();
            mPath             = mData.Path;
            mThumbnailPath    = mData.ThumbnailPath;
            texture2DAddPhoto = mResLoader.LoadSync <Texture2D>("attendance_main_add");
            BtnBack.onClick.AddListener(() => {
                AudioManager.PlaySound("Button_Audio");
                Back();
            });
            BtnCancel.onClick.AddListener(() => {
                AudioManager.PlaySound("Button_Audio");
                Back();
            });
            BtnPush.onClick.AddListener(() =>
            {
                AudioManager.PlaySound("Button_Audio");
                // if (InputContent.text.IsNullOrEmpty())
                // {
                //     CommonUtil.toast("请输入内容");
                //     Log.I("请输入内容");
                //     return;
                // }
                if (mPath.IsNullOrEmpty())
                {
                    if (mData.Action == AttendanceAdd.Pic)
                    {
                        CommonUtil.toast("请添加图片");
                        Log.I("请添加图片");
                    }
                    else if (mData.Action == AttendanceAdd.Audio)
                    {
                        CommonUtil.toast("请添加音频");
                        Log.I("请添加音频");
                    }
                    else if (mData.Action == AttendanceAdd.Video)
                    {
                        CommonUtil.toast("请添加视频");
                        Log.I("请添加视频");
                    }
                    return;
                }
                LoadingManager.GetInstance().CreatLoading();
                BtnPush.enabled = false;
                if (mData.Action == AttendanceAdd.Pic)
                {
                    string fileType = mPath.Substring(mPath.LastIndexOf("."));
                    Log.I("mPath: " + mPath + " fileType: " + fileType);
                    StartRequestForUpload("attendance" + fileType, mPath);
                }
                else if (mData.Action == AttendanceAdd.Audio)
                {
                    MicrophoneManager.GetInstance().StopPlay();
                    string fileType = mPath.Substring(mPath.LastIndexOf("."));
                    Log.I("mPath: " + mPath + " fileType: " + fileType);
                    StartRequestForUpload("attendance" + fileType, mPath);
                }
                else if (mData.Action == AttendanceAdd.Video)
                {
                    if (Application.platform == RuntimePlatform.Android)
                    {
                        // CommonUtil.toast("视频压缩上传中,请稍等");
                        AndroidForUnity.CallAndroidForVideoCompress(mPath);
                    }
                    else
                    {
                        StartCoroutine(IPhonePlayerCompressFinished());
                    }
                }
            });
            BtnAdd.onClick.AddListener(() =>
            {
                AudioManager.PlaySound("Button_Audio");
                if (mData.Action == AttendanceAdd.Audio)
                {
                    UIMgr.OpenPanel <AttendanceAudioRecordPanel>(new AttendanceAudioRecordPanelData(), UITransitionType.CIRCLE);
                }
                else
                { //unityForPlayVideo
                    if (mPath.IsNullOrEmpty())
                    {
                        if (mData.Action == AttendanceAdd.Pic)
                        {
                            UIMgr.OpenPanel <ChoosePhotoPanel>(new ChoosePhotoPanelData()
                            {
                                action = ChoosePhotoAction.AttendancePic,
                            });
                        }
                        else if (mData.Action == AttendanceAdd.Video)
                        {
                            // UIMgr.OpenPanel<ChoosePhotoPanel>(new ChoosePhotoPanelData()
                            // {
                            //     action = ChoosePhotoAction.AttendanceVideo,
                            //     showTip = true
                            //
                            // });
                            if (Application.platform == RuntimePlatform.IPhonePlayer)
                            {
                                IPhonePlayerMakeVideoOpenCamera();
                            }
                            else if (Application.platform == RuntimePlatform.Android)
                            {
                                NativeGallery.RequestPermission((result, action) =>
                                {
                                    if (result == (int)NativeGallery.Permission.Granted)
                                    {
                                        NativeGallery.GetVideoFromGalleryForAndroid((json) =>
                                        {
                                            if (json.IsNotNullAndEmpty())
                                            {
                                                NativeVideoModel model = SerializeHelper.FromJson <NativeVideoModel>(json);
                                                if (model.IsNotNull())
                                                {
                                                    if (model.status == 1)
                                                    {
                                                        mPath          = model.videoPath;
                                                        mThumbnailPath = model.imagePath;
                                                        AudioContent.gameObject.SetActive(false);
                                                        if (model.imagePath.IsNotNullAndEmpty())
                                                        {
                                                            ImageDownloadUtils.Instance.SetAsyncImage("file://" + model.imagePath, ImagePic);
                                                            BtnVideo.gameObject.SetActive(true);
                                                            BtnDel.gameObject.SetActive(true);
                                                        }
                                                    }
                                                    else if (model.status == 0)
                                                    {
                                                        mPath           = null;
                                                        mThumbnailPath  = null;
                                                        ImagePic.sprite = Sprite.Create(texture2DAddPhoto, new Rect(0, 0, texture2DAddPhoto.width, texture2DAddPhoto.height), Vector2.one * 0.5f);
                                                        BtnVideo.gameObject.SetActive(false);
                                                        BtnDel.gameObject.SetActive(false);
                                                    }
                                                }
                                            }
                                        }, "选择视频", "video/*", action);
                                    }
                                }, (int)NativeAction.Camera);
                            }
                        }
                    }
                    else
                    {
                        if (mData.Action == AttendanceAdd.Pic)
                        {
                            if (Application.platform == RuntimePlatform.Android)
                            {
                                AndroidForUnity.CallAndroidForShowPic(mPath);
                            }
                            else if (Application.platform == RuntimePlatform.IPhonePlayer)
                            {
                                UIMgr.OpenPanel <PhotoBrowserPanel>(new PhotoBrowserPanelData()
                                {
                                    ImageUrl = mPath,
                                }, UITransitionType.NULL);
                            }
                        }
                        else if (mData.Action == AttendanceAdd.Video)
                        {
                            if (Application.platform == RuntimePlatform.Android)
                            {
                                AndroidForUnity.CallAndroidForPlayVideo(mPath);
                            }
                            else if (Application.platform == RuntimePlatform.IPhonePlayer)
                            {
                                Dictionary <string, object> paramDic = new Dictionary <string, object>();
                                Dictionary <string, object> subParam = new Dictionary <string, object>();
                                subParam.Add("url", mPath);
                                paramDic.Add("target", AppConst.VIDEO_IOS);
                                paramDic.Add("method", IOSClientUtil.VideoMediaPlay);
                                paramDic.Add("params", subParam);
                                IOSClientUtil.CommonMethodCallIOSClient(paramDic.ToJson());
                            }
                        }
                    }
                }
            });
            BtnVideo.onClick.AddListener(() =>
            {
                AudioManager.PlaySound("Button_Audio");
                if (mData.Action == AttendanceAdd.Video)
                {
                    if (Application.platform == RuntimePlatform.Android)
                    {
                        AndroidForUnity.CallAndroidForPlayVideo(mPath);
                    }
                    else if (Application.platform == RuntimePlatform.IPhonePlayer)
                    {
                        Dictionary <string, object> paramDic = new Dictionary <string, object>();
                        Dictionary <string, object> subParam = new Dictionary <string, object>();
                        subParam.Add("url", mPath);
                        paramDic.Add("target", AppConst.VIDEO_IOS);
                        paramDic.Add("method", IOSClientUtil.VideoMediaPlay);
                        paramDic.Add("params", subParam);
                        IOSClientUtil.CommonMethodCallIOSClient(paramDic.ToJson());
                    }
                }
            });
            if (mData.Action == AttendanceAdd.Audio)
            {
                UpdateTvTime("0");
                AddContent.gameObject.SetActive(mPath.IsNullOrEmpty());
                AudioContent.gameObject.SetActive(mPath.IsNotNullAndEmpty());
                TextAdd.text = "添加语音";
            }
            else
            {
                if (mData.Action == AttendanceAdd.Pic)
                {
                    TextAdd.text = "添加图片";
                    AudioContent.gameObject.SetActive(false);
                    if (mPath.IsNotNullAndEmpty())
                    {
                        ImageDownloadUtils.Instance.SetAsyncImage("file://" + mThumbnailPath, ImagePic);
                        BtnVideo.gameObject.SetActive(false);
                        BtnDel.gameObject.SetActive(true);
                    }
                }
                else
                {
                    TextAdd.text = "添加视频";
                    AudioContent.gameObject.SetActive(false);
                    if (mPath.IsNotNullAndEmpty())
                    {
                        ImageDownloadUtils.Instance.SetAsyncImage("file://" + mThumbnailPath, ImagePic);
                        BtnVideo.gameObject.SetActive(true);
                        BtnDel.gameObject.SetActive(true);
                    }
                }
            }
            BtnPlayAndPause.onClick.AddListener(() =>
            {
                if (mPath.IsNotNullAndEmpty())
                {
                    if (mPlayStatus == PlayStatus.NoPlaying || mPlayStatus == PlayStatus.Stop)
                    {
                        MicrophoneManager.GetInstance().PlayRecord();
                    }
                    else if (mPlayStatus == PlayStatus.Playing)
                    {
                        MicrophoneManager.GetInstance().PausePlay();
                    }
                    else if (mPlayStatus == PlayStatus.Pause)
                    {
                        MicrophoneManager.GetInstance().PlayRecord(MicrophoneManager.GetInstance().mPlayingTime.Value);
                    }
                }
            });
            BtnClose.onClick.AddListener(() =>
            {
                AudioManager.PlaySound("Button_Audio");
                mPath = null;
                MicrophoneManager.GetInstance().StopPlay();
                AddContent.gameObject.SetActive(mPath.IsNullOrEmpty());
                AudioContent.gameObject.SetActive(mPath.IsNotNullAndEmpty());
            });
            BtnDel.onClick.AddListener(() =>
            {
                AudioManager.PlaySound("Button_Audio");
                // 弹窗
                UIMgr.OpenPanel <TipPanel>(new TipPanelData()
                {
                    action  = TipAction.DelAttendance,
                    message = "确定要删除当前内容吗?",
                });
            });
            InputContent.onValueChange.AddListener(EditChange);

            if (mData.Action == AttendanceAdd.Audio)
            {
                MicrophoneManager.GetInstance().mPlayStatus.Subscribe(status =>
                {
                    mPlayStatus = status;
                    if (mPlayStatus == PlayStatus.Playing)
                    {
                        // var soundOnTexture = mResLoader.LoadSync<Texture2D>("ic_audio_playing");
                        // ImgPlayAndPause.sprite = Sprite.Create(soundOnTexture, new Rect(0, 0, soundOnTexture.width, soundOnTexture.height), Vector2.one * 0.5f);
                        ImgPlayAndPause.gameObject.SetActive(false);
                        ImgPlaying.gameObject.SetActive(true);
                    }
                    else
                    {
                        // var soundOnTexture = mResLoader.LoadSync<Texture2D>("ic_audiio_pause");
                        // ImgPlayAndPause.sprite = Sprite.Create(soundOnTexture, new Rect(0, 0, soundOnTexture.width, soundOnTexture.height), Vector2.one * 0.5f);
                        ImgPlayAndPause.gameObject.SetActive(true);
                        ImgPlaying.gameObject.SetActive(false);
                    }

                    if (mPlayStatus == PlayStatus.Stop)
                    {
                        UpdateTvTime("0");
                    }
                }).AddTo(this);
            }
            SimpleEventSystem.GetEvent <RecordPath>().Subscribe(Path =>
            {
                mPath = Path.Path;
                UpdateTvTime("0");
                AddContent.gameObject.SetActive(mPath.IsNullOrEmpty());
                AudioContent.gameObject.SetActive(mPath.IsNotNullAndEmpty());
            }).AddTo(this);
            SimpleEventSystem.GetEvent <ChoosePhotoClick>()
            .Subscribe(_ =>
            {
                if (_.GetPhotoAction == ChoosePhotoAction.AttendancePic)
                {
                    if (Application.platform == RuntimePlatform.IPhonePlayer)
                    {
                        if (_.GetAction == NativeAction.Camera)
                        {
                            IPhonePlayerSelectPictureOpenCamera();
                        }
                        else if (_.GetAction == NativeAction.Album)
                        {
                            IPhonePlayerSelectPictureOpenAlbum();
                        }
                    }
                    else if (Application.platform == RuntimePlatform.Android)
                    {
                        NativeGallery.RequestPermission((result, action) =>
                        {
                            if (result == (int)NativeGallery.Permission.Granted)
                            {
                                NativeGallery.GetImageFromGalleryForAndroid((path) =>
                                {
                                    if (path.IsNotNullAndEmpty())
                                    {
                                        mPath          = path;
                                        mThumbnailPath = path;
                                        AudioContent.gameObject.SetActive(false);
                                        if (mPath.IsNotNullAndEmpty())
                                        {
                                            ImageDownloadUtils.Instance.SetAsyncImage("file://" + mThumbnailPath, ImagePic);
                                            BtnVideo.gameObject.SetActive(false);
                                            BtnDel.gameObject.SetActive(true);
                                        }
                                    }
                                    Debug.Log("Image path: " + path);
                                }, "选择图片", "image/*", true, action);
                            }
                        }, (int)_.GetAction);
                    }
                }
                // 视频不需要了
                else if (_.GetPhotoAction == ChoosePhotoAction.AttendanceVideo)
                {
                    NativeGallery.RequestPermission((result, action) =>
                    {
                        if (result == (int)NativeGallery.Permission.Granted)
                        {
                            NativeGallery.GetVideoFromGalleryForAndroid((json) =>
                            {
                                if (json.IsNotNullAndEmpty())
                                {
                                    NativeVideoModel model = SerializeHelper.FromJson <NativeVideoModel>(json);
                                    if (model.IsNotNull())
                                    {
                                        if (model.status == 1)
                                        {
                                            mPath          = model.videoPath;
                                            mThumbnailPath = model.imagePath;
                                            AudioContent.gameObject.SetActive(false);
                                            if (model.imagePath.IsNotNullAndEmpty())
                                            {
                                                ImageDownloadUtils.Instance.SetAsyncImage("file://" + model.imagePath, ImagePic);
                                                BtnVideo.gameObject.SetActive(true);
                                                BtnDel.gameObject.SetActive(true);
                                            }
                                        }
                                        else if (model.status == 0)
                                        {
                                            mPath           = null;
                                            mThumbnailPath  = null;
                                            ImagePic.sprite = Sprite.Create(texture2DAddPhoto, new Rect(0, 0, texture2DAddPhoto.width, texture2DAddPhoto.height), Vector2.one * 0.5f);
                                            BtnVideo.gameObject.SetActive(false);
                                            BtnDel.gameObject.SetActive(false);
                                        }
                                    }
                                }
                            }, "选择视频", "video/*", action);
                        }
                    }, (int)_.GetAction);
                }
            }).AddTo(this);
            SimpleEventSystem.GetEvent <TipConfirmClick>()
            .Subscribe(_ =>
            {
                if (_.GetAction == TipAction.DelAttendance)
                {
                    mPath           = null;
                    mThumbnailPath  = null;
                    ImagePic.sprite = Sprite.Create(texture2DAddPhoto, new Rect(0, 0, texture2DAddPhoto.width, texture2DAddPhoto.height), Vector2.one * 0.5f);
                    BtnVideo.gameObject.SetActive(false);
                    BtnDel.gameObject.SetActive(false);
                }
            }).AddTo(this);
            SimpleEventSystem.GetEvent <VideoCompressResult>().Subscribe(res =>
            {
                VideoCompressModel model = res.Model;

                if (Application.platform == RuntimePlatform.Android)
                {
                    if (model.status == 1)
                    {
                        string fileType = model.path.Substring(model.path.LastIndexOf("."));
                        Log.I("mPath: " + model.path + " fileType: " + fileType);
                        StartRequestForUpload("attendance" + fileType, model.path);
                    }
                    else
                    {
                        CommonUtil.toast("视频压缩失败");
                    }
                }
                else if (Application.platform == RuntimePlatform.IPhonePlayer)
                {
                }
            }).AddTo(this);
        }