### Start Recording Audio Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Starts the audio recording process. Updates the UI to indicate that recording is in progress. ```javascript function startRecordAudio() { h5packBridge.recordAudio.start().then(res => { console.log('开始录音', res); showResult('recordAudioRes', '录音中...'); }); } ``` -------------------------------- ### Get Current Location Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Retrieves the device's current geographical location. Displays the latitude, longitude, and accuracy, or an error message if retrieval fails. Handles permission and service errors by prompting the user to open settings. ```javascript function getCurrentPosition() { showResult('position', '定位中...'); h5packBridge.location .getCurrentPosition() .then(res => { console.log('地址res', res); var lat = res.coords.latitude; var lng = res.coords.longitude; var acc = res.coords.accuracy; showResult('position', '纬度:' + lat + '\n经度:' + lng + '\n精度:' + acc + 'm'); }) .catch(err => { console.error('定位失败', err); showResult('position', '错误:' + err.code + '\n' + err.message); if (err.code === 'LOCATION_PERMISSION_NEVER_ASK_AGAIN') { if (confirm('定位权限被永久拒绝,是否打开应用设置页?')) { h5packBridge.location.openAppSettings(); } } else if (err.code === 'LOCATION_SERVICES_DISABLED') { if (confirm('定位服务未开启,是否打开定位设置?')) { h5packBridge.location.openLocationSettings(); } } }); } ``` -------------------------------- ### Open Record Audio App Settings Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Opens the application's settings page where users can manage microphone permissions. ```javascript function openRecordAppSettings() { h5packBridge.recordAudio.openAppSettings(); } ``` -------------------------------- ### Open Camera App Settings Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Opens the application's settings page where users can manage camera permissions. ```javascript function openCameraAppSettings() { h5packBridge.camera.openAppSettings(); } ``` -------------------------------- ### Open Camera to Take Photo Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Launches the device's camera interface to allow the user to take a photo. The base64 encoded image is then set as the source for an element with the ID 'cameraPreview'. ```javascript function openCamera() { h5packBridge.camera.open().then(res => { console.log('拍照res', res); document.getElementById('cameraPreview').src = res?.base64; }); } ``` -------------------------------- ### Request Record Audio Permission Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Requests permission to record audio. Handles granted, denied, and 'never ask again' scenarios, including opening app settings if necessary. ```javascript function requestRecordAudioPermission() { h5packBridge.recordAudio.requestPermission().then(res => { console.log('申请录音权限', res); if (res.granted) { alert('录音权限已授权'); } else if (res.status === 'never_ask_again') { if (confirm('麦克风权限被永久拒绝,是否打开应用设置页?')) { h5packBridge.recordAudio.openAppSettings(); } } else { alert('录音权限被拒绝'); } }); } ``` -------------------------------- ### Choose Image from Gallery Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Opens the device's image gallery to allow the user to select an image. The base64 encoded image is then set as the source for an element with the ID 'cameraPreview'. ```javascript function chooseImage() { h5packBridge.camera.chooseImage().then(res => { console.log('相册res', res); document.getElementById('cameraPreview').src = res[0]?.base64; }); } ``` -------------------------------- ### Open Location Settings Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Opens the device's location settings page. ```javascript function openLocationSettings() { h5packBridge.location.openLocationSettings(); } ``` -------------------------------- ### Check Record Audio Permission Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Checks if the application has permission to record audio. Logs the permission status and displays an alert. ```javascript function checkRecordAudioPermission() { h5packBridge.recordAudio.checkPermission().then(res => { console.log('录音权限', res); alert('录音权限:' + (res ? '已授权' : '未授权')); }); } ``` -------------------------------- ### Open App Settings for Location Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Opens the application's settings page where users can manage location permissions. ```javascript function openAppSettings() { h5packBridge.location.openAppSettings(); } ``` -------------------------------- ### Request Camera Permission Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Requests permission to use the camera. Handles granted, denied, and 'never ask again' scenarios, including opening app settings if necessary. ```javascript function requestCameraPermission() { h5packBridge.camera.requestPermission().then(res => { console.log('申请相机权限', res); if (res.granted) { alert('相机权限已授权'); } else if (res.status === 'never_ask_again') { if (confirm('相机权限被永久拒绝,是否打开应用设置页?')) { h5packBridge.camera.openAppSettings(); } } else { alert('相机权限被拒绝'); } }); } ``` -------------------------------- ### Scan QR Code Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Initiates the device's camera to scan a QR code. The result is displayed using the `showResult` utility function. ```javascript function scan() { h5packBridge.camera.scan().then(res => { showResult('scanRes', '扫码结果:' + res); }); } ``` -------------------------------- ### Check Camera Permission Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Checks if the application has permission to use the camera. Logs the permission status and displays an alert. ```javascript function checkCameraPermission() { h5packBridge.camera.checkPermission().then(res => { console.log('相机权限', res); alert('相机权限:' + (res ? '已授权' : '未授权')); }); } ``` -------------------------------- ### Play Recorded Audio Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Plays the recorded audio file specified by `currentRecordPath`. Alerts the user if no recording has been made yet. Updates the UI with playback status. ```javascript function playRecordAudio() { if (!currentRecordPath) { alert('请先录音'); return; } h5packBridge.recordAudio.play(currentRecordPath).then(() => { console.log('播放中', currentRecordPath); showResult('playbackStatus', '正在播放:' + currentRecordPath); }); } ``` -------------------------------- ### Restart Recording Audio Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Restarts the audio recording process. Updates the UI to indicate that recording is in progress again. ```javascript function restartRecordAudio() { h5packBridge.recordAudio.restart().then(res => { console.log('重新录音', res); showResult('recordAudioRes', '重新录音中...'); }); } ``` -------------------------------- ### Request Location Permission Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Requests permission to access the device's location. Handles granted, denied, and 'never ask again' scenarios, including opening app settings if necessary. ```javascript function requestLocationPermission() { h5packBridge.location.requestPermission().then(res => { console.log('申请定位权限', res); if (res.granted) { alert('定位权限已授权'); } else if (res.status === 'never_ask_again') { if (confirm('定位权限被永久拒绝,是否打开应用设置页?')) { h5packBridge.location.openAppSettings(); } } else { alert('定位权限被拒绝'); } }); } ``` -------------------------------- ### Check Location Permission Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Checks if the application has permission to access the device's location. Logs the permission status and displays an alert. ```javascript function checkLocationPermission() { h5packBridge.location.checkPermission().then(granted => { console.log('定位权限', granted); alert('定位权限:' + (granted ? '已授权' : '未授权')); }); } ``` -------------------------------- ### Cancel Recording Audio Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Cancels the current audio recording process. Clears the stored path and updates the UI to indicate cancellation. ```javascript function cancelRecordAudio() { h5packBridge.recordAudio.cancel().then(() => { currentRecordPath = ''; showResult('recordAudioRes', '录音已取消'); }); } ``` -------------------------------- ### Check Location Service Status Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Checks if the device's location services are enabled. Logs the status and displays an alert. ```javascript function checkLocationEnabled() { h5packBridge.location.checkLocationEnabled().then(enabled => { console.log('定位服务', enabled); alert('定位服务:' + (enabled ? '已开启' : '未开启')); }); } ``` -------------------------------- ### Stop Recording Audio Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Stops the current audio recording. Stores the path of the recorded file and updates the UI with the duration and path. ```javascript function stopRecordAudio() { h5packBridge.recordAudio.stop().then(res => { console.log('停止录音', res); currentRecordPath = res.path; showResult('recordAudioRes', '录音完成:' + res.durationMs + 'ms\n路径:' + res.path); }); } ``` -------------------------------- ### Stop Playing Recorded Audio Source: https://github.com/jimmylxue/h5pack-core/blob/main/dist/index.html Stops the playback of the currently playing recorded audio file. Updates the UI to indicate that playback has stopped. ```javascript function stopPlayRecordAudio() { h5packBridge.recordAudio.stopPlay().then(() => { console.log('停止播放'); showResult('playbackStatus', '播放已停止'); }); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.