国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

實(shí)例詳解uniapp如何實(shí)現(xiàn)電話錄音功能(附代碼)

藏色散人
發(fā)布: 2023-01-05 16:41:12
轉(zhuǎn)載
4713人瀏覽過(guò)

本篇文章給大家?guī)?lái)了關(guān)于uniapp的相關(guān)知識(shí),其中主要介紹了怎么用uniapp實(shí)現(xiàn)撥打電話并且還能同步錄音的功能,感興趣的朋友一起來(lái)看一下吧,希望對(duì)大家有幫助。

實(shí)例詳解uniapp如何實(shí)現(xiàn)電話錄音功能(附代碼)

uniapp 實(shí)現(xiàn)打電話錄音功能

最近需要實(shí)現(xiàn)一個(gè)通過(guò) uniapp 調(diào)用手機(jī)撥打電話的功能,撥打之后同時(shí)錄音,掛斷電話之后將錄音文件進(jìn)行上傳,現(xiàn)在將幾個(gè)核心代碼分享給大家!

const recorderManager = uni.getRecorderManager();
onLoad(option) {
            let self = this;
            recorderManager.onStop(function (res) {
                console.log("res",res)
                self.end_time = Math.round(new Date().getTime() / 1000);
                let voicePath = res.tempFilePath;
                self.voicePath = voicePath;
                self.closeTimeOut();
                uni.showToast({
                    icon: 'loading',
                    title: "請(qǐng)稍后...",
                    duration: 0
                });
                uni.uploadFile({
                    url: self.upload_url,
                    filePath: voicePath,
                    name: "file",
                    formData: {
                        id: self.phoneInfo.id,
                        start_time: self.start_time,
                        end_time: self.end_time,
                        phone: self.phoneNumber
                    },
                    header: {
                        Authorization: "Bearer " + uni.getStorageSync(EnumData.token)
                    },
                    success: (res) => {
                        // console.log("文件上傳成功")
                        console.log(res.data);
                    },
                    fail(err) {
                        console.log("文件上傳失敗")
                        console.log(err);
                    },
                    complete() {
                        self.start_time = 0;
                        self.end_time = 0;
                        uni.hideToast();
                    }
                })
            });
            this.getCallStatus();
}
getCallStatus() {
    let that = this;
    let maintest = plus.android.runtimeMainActivity();
    let Contexttest = plus.android.importClass("android.content.Context");
    let telephonyManager = plus.android.importClass("android.telephony.TelephonyManager");
    let telManager = plus.android.runtimeMainActivity().getSystemService(Contexttest.TELEPHONY_SERVICE);
    let receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {
        onReceive: function (Contexttest, intent) {
            plus.android.importClass(intent);
            let phoneStatus = telManager.getCallState();
            that.callStatus = phoneStatus; //電話狀態(tài) 0->空閑狀態(tài) 1->振鈴狀態(tài) 2->通話存在
            switch (phoneStatus) {
                case 0:
                    console.log("3、電話掛斷,上傳錄音")
                    // 結(jié)束錄音
                    recorderManager.stop();
                    break;
                case 1:
                    // console.log('1、振鈴狀態(tài)');
                    break;
                case 2:
                    console.log('2、通話存在')
                    // 延遲錄音
                    that.start_time = Math.round(new Date().getTime() / 1000);
                    recorderManager.start({
                        duration: EnumData.audioDuration, // 時(shí)長(zhǎng) 10分鐘
                        sampleRate: EnumData.audioSampleRate, // 碼率
                    });
                    break;
            }
        }
    });
    let IntentFilter = plus.android.importClass('android.content.IntentFilter');
    let filter = new IntentFilter();
    filter.addAction(telephonyManager.ACTION_PHONE_STATE_CHANGED);
    maintest.registerReceiver(receiver, filter);
},
登錄后復(fù)制

需要申請(qǐng)的權(quán)限,可以放到 App.vue 中

if (plus.os.name == 'Android') {
      plus.android.requestPermissions(
         ['android.permission.ANSWER_PHONE_CALLS',//手動(dòng) 掛斷和接聽(tīng) 需要這個(gè)權(quán)限
          "android.permission.MODIFY_AUDIO_SETTINGS",//手動(dòng) 掛斷和接聽(tīng) 需要這個(gè)權(quán)限
          "android.permission.CALL_PHONE",//手動(dòng) 掛斷和接聽(tīng) 需要這個(gè)權(quán)限
          "android.permission.READ_PHONE_STATE",//>監(jiān)聽(tīng)電話狀態(tài) 需要這個(gè)權(quán)限
          "android.permission.READ_CALL_LOG",//獲取號(hào)碼需要這個(gè)權(quán)限
          "android.permission.READ_AUDIO" // 錄音權(quán)限
          ],
      function(resultObj) {
          var result = 0;
          for (var i = 0; i < resultObj.granted.length; i++) {
          var grantedPermission = resultObj.granted[i];
          console.log('已獲取的權(quán)限:' + grantedPermission);
          result = 1
      }
      for (var i = 0; i < resultObj.deniedPresent.length; i++) {
          var deniedPresentPermission = resultObj.deniedPresent[i];
          console.log('拒絕本次申請(qǐng)的權(quán)限:' + deniedPresentPermission);
          result = 0
      }
      for (var i = 0; i < resultObj.deniedAlways.length; i++) {
          var deniedAlwaysPermission = resultObj.deniedAlways[i];
          console.log('永久拒絕申請(qǐng)的權(quán)限:' + deniedAlwaysPermission);
          result = -1
      }
     },  function(error) {
          console.log('申請(qǐng)權(quán)限錯(cuò)誤:' + error.code + " = " + error.message);
     } );
}
登錄后復(fù)制

注意點(diǎn)

  • 調(diào)試模式下可以正常監(jiān)聽(tīng)通話掛斷并且上傳文件的,但是打包之后就失效?

一般的手機(jī)打包是可以正常使用的,我用的是 oneplus7 , 打包后安裝正常使用,部分手機(jī)需要到系統(tǒng)設(shè)置的權(quán)限中,將應(yīng)用的【開(kāi)啟手機(jī)設(shè)備狀態(tài)碼】進(jìn)行開(kāi)啟即可,目前遇到的就這個(gè)。

推薦學(xué)習(xí):《uni-app視頻教程

以上就是實(shí)例詳解uniapp如何實(shí)現(xiàn)電話錄音功能(附代碼)的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!

最佳 Windows 性能的頂級(jí)免費(fèi)優(yōu)化軟件
最佳 Windows 性能的頂級(jí)免費(fèi)優(yōu)化軟件

每個(gè)人都需要一臺(tái)速度更快、更穩(wěn)定的 PC。隨著時(shí)間的推移,垃圾文件、舊注冊(cè)表數(shù)據(jù)和不必要的后臺(tái)進(jìn)程會(huì)占用資源并降低性能。幸運(yùn)的是,許多工具可以讓 Windows 保持平穩(wěn)運(yùn)行。

下載
來(lái)源:learnku網(wǎng)
本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請(qǐng)聯(lián)系admin@php.cn
最新問(wèn)題
開(kāi)源免費(fèi)商場(chǎng)系統(tǒng)廣告
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
關(guān)于我們 免責(zé)申明 意見(jiàn)反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓(xùn),幫助PHP學(xué)習(xí)者快速成長(zhǎng)!
關(guān)注服務(wù)號(hào) 技術(shù)交流群
PHP中文網(wǎng)訂閱號(hào)
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時(shí)隨地碎片化學(xué)習(xí)
PHP中文網(wǎng)抖音號(hào)
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://www.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)