private void Update() { if (mPlayStatus == PlayStatus.Playing) { UpdateTvTime(MicrophoneManager.GetInstance().mPlayingTime.ToString()); } }
protected override void OnClose() { if (MicrophoneManager.GetInstance().mRecordStatus.Value == RecordStatus.Recording) { MicrophoneManager.GetInstance().PauseRecord(); } MicrophoneManager.GetInstance().mRecordStatus.Value = RecordStatus.NoRecord; MicrophoneManager.GetInstance().mPlayStatus.Value = PlayStatus.NoPlaying; MicrophoneManager.GetInstance().Destory(); if (mResLoader.IsNotNull()) { mResLoader.Recycle2Cache(); mResLoader = null; } }
void StartRequestForPunch(string filePath) { Dictionary <string, object> paramDict = new Dictionary <string, object>(); paramDict.Add("babyId", PlayerPrefsUtil.GetBabyId()); paramDict.Add("relBoxId", mData.BoxId); paramDict.Add("boxDay", mData.BoxDay); if (mData.Action == AttendanceAdd.Audio) { paramDict.Add("duration", (int)(MicrophoneManager.GetInstance().GetClipLength() * 1000)); } paramDict.Add("punchText", InputContent.text); paramDict.Add("punchType", (int)mData.Action); paramDict.Add("punchPath", filePath); HttpUtil.PostWithSign <AttendanceModel>(UrlConst.Punch, paramDict) .Subscribe(response => { LoadingManager.GetInstance().DismissLoading(); if (PlayerPrefsUtil.LockModels[PlayerPrefsUtil.GetBoxMonthIndex()].boxDayList.IsNull()) { PlayerPrefsUtil.LockModels[PlayerPrefsUtil.GetBoxMonthIndex()].boxDayList = new List <int>(); } if (PlayerPrefsUtil.LockModels[PlayerPrefsUtil.GetBoxMonthIndex()].boxDayList .Contains(mData.BoxDay)) { PlayerPrefsUtil.LockModels[PlayerPrefsUtil.GetBoxMonthIndex()].boxDayList.Remove(mData.BoxDay); } PlayerPrefsUtil.LockModels[PlayerPrefsUtil.GetBoxMonthIndex()].boxDayList.Add(mData.BoxDay); Log.I("发布:" + mData.Action); BtnPush.enabled = true; SimpleEventSystem.Publish(new AttendanceSuccess(true)); UIMgr.OpenPanel <AttendanceSharePanel>(new AttendanceSharePanelData() { AttendanceModel = response }, UITransitionType.CIRCLE); Close(); } , e => { BtnPush.enabled = true; if (e is HttpException) { HttpException http = e as HttpException; } }).AddTo(this); }
private void Update() { if (TvTime.IsActive()) { TvTime.text = StringUtil.SecondsToMinutes((int)MicrophoneManager.GetInstance().mRecordTime); if ((int)MicrophoneManager.GetInstance().mRecordTime == (MicrophoneManager.RECORD_TIME - 1)) { if (MicrophoneManager.GetInstance().mRecordStatus.Value != RecordStatus.RecordComplete) { MicrophoneManager.GetInstance().StopRecord(); } } else if (((int)MicrophoneManager.GetInstance().mRecordTime) >= (MicrophoneManager.RECORD_TIME - 1 - 10)) { string time = "<color=#FF9E47>" + (MicrophoneManager.RECORD_TIME - 1 - (int)MicrophoneManager.GetInstance().mRecordTime) + "s </color>"; TvRecord.text = "录制中...\n" + time + " 结束录音"; } else { TvRecord.text = "录制中...\n点击完成结束录音"; } } }
protected override void OnInit(QFramework.IUIData uiData) { mData = uiData as AttendanceAudioRecordPanelData ?? new AttendanceAudioRecordPanelData(); BtnBack.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); Back(); }); BtnRecord.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); if (MicrophoneManager.GetInstance().mRecordStatus.Value == RecordStatus.NoRecord) { MicrophoneManager.GetInstance().StartRecord(); } else if (MicrophoneManager.GetInstance().mRecordStatus.Value == RecordStatus.Recording) { MicrophoneManager.GetInstance().PauseRecord(); } else if (MicrophoneManager.GetInstance().mRecordStatus.Value == RecordStatus.Pause) { MicrophoneManager.GetInstance().StartRecord(); } }); BtnComplete.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); if ((int)MicrophoneManager.GetInstance().mRecordTime < MicrophoneManager.MIN_TIME) { CommonUtil.toast("音频时长过短"); Log.I("音频时长过短"); } else { MicrophoneManager.GetInstance().StopRecord(); } }); MicrophoneManager.GetInstance().mRecordStatus.Subscribe(RecordStatus => { if (RecordStatus == RecordStatus.NoRecord) { var soundOnTexture = mResLoader.LoadSync <Texture2D>("audio_record"); BtnRecord.GetComponent <Image>().sprite = Sprite.Create(soundOnTexture, new Rect(0, 0, soundOnTexture.width, soundOnTexture.height), Vector2.one * 0.5f); TvTime.gameObject.SetActive(false); BtnComplete.gameObject.SetActive(false); // <b>加粗</b> string time = "<color=#FF9E47><size=24>音频5分钟内</size></color>"; TvRecord.text = "点击开始录音\n" + time; } else if (RecordStatus == RecordStatus.Recording) { var soundOnTexture = mResLoader.LoadSync <Texture2D>("audio_recording"); BtnRecord.GetComponent <Image>().sprite = Sprite.Create(soundOnTexture, new Rect(0, 0, soundOnTexture.width, soundOnTexture.height), Vector2.one * 0.5f); TvTime.gameObject.SetActive(true); BtnComplete.gameObject.SetActive(true); TvRecord.text = "录制中...\n点击完成结束录音"; } else if (RecordStatus == RecordStatus.Pause) { var soundOnTexture = mResLoader.LoadSync <Texture2D>("audio_pause_record"); BtnRecord.GetComponent <Image>().sprite = Sprite.Create(soundOnTexture, new Rect(0, 0, soundOnTexture.width, soundOnTexture.height), Vector2.one * 0.5f); TvTime.gameObject.SetActive(true); BtnComplete.gameObject.SetActive(true); TvRecord.text = "暂停"; } else if (RecordStatus == RecordStatus.RecordComplete) { MicrophoneManager.GetInstance().Save(out path); if (path.IsNotNullAndEmpty()) { SimpleEventSystem.Publish(new RecordPath(path)); } Close(); } }).AddTo(this); }
/** * 重新播放音频 */ public void ReloadPlayMusic(string json) { MicrophoneManager.GetInstance().StartRecord(); MicrophoneManager.GetInstance().PauseRecord(); Debug.Log("ReloadPlayMusic" + " - END"); }
private void UpdateTvTime(string playTime) { TextTime.text = playTime + "\"" + "/" + ((int)MicrophoneManager.GetInstance().GetClipLength()).ToString() + "\""; }
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); }