Skip to content

Commit

Permalink
Merge pull request #163 from tangcq-code/release-3.6.8-app
Browse files Browse the repository at this point in the history
fix: 增加createAudioContext等接口的实现,补齐playground的样例
  • Loading branch information
szzwk authored Sep 4, 2023
2 parents e9fe2a7 + 0f470f7 commit c29e5a6
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 5 deletions.
18 changes: 16 additions & 2 deletions examples/mini-program-example/src/pages/api/analysis/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Taro from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import ButtonList from '@/components/buttonList'
import './index.scss'
import { TestConsole } from '@/util/util'

/**
* 数据分析
Expand All @@ -22,11 +23,24 @@ export default class Index extends React.Component {
},
{
id: 'reportAnalytics',
func: null,
inputData: {
eventName: '',
data: {},
},
func: (apiIndex, inData) => {
TestConsole.consoleTest('reportAnalytics')
Taro.reportAnalytics(inData.eventName, inData.data)
},
},
{
id: 'getExptInfoSync',
func: null,
inputData: {
key: [],
},
func: (apiIndex, inData) => {
TestConsole.consoleTest('getExptInfoSync')
Taro.getExptInfoSync(inData.key)
},
},
],
}
Expand Down
106 changes: 106 additions & 0 deletions examples/mini-program-example/src/pages/api/file/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,112 @@ export default class Index extends React.Component {
TestConsole.consoleNormal('closeSync success ', openFd)
},
},
{
id: 'fileSystem_getFileInfo',
func: (apiIndex) => {
TestConsole.consoleTest('fileSystem_getFileInfo')
Taro.chooseImage({
success: (res) => {
var tempFilePaths = res.tempFilePaths
Taro.saveFile({
tempFilePath: tempFilePaths[0],
filePath: 'D:/common',
success: (res) => {
TestConsole.consoleNormal('saveFile success ', res)
fileSystemManager.getFileInfo({
filePath: res.savedFilePath,
success: (res) => {
TestConsole.consoleSuccess.call(this, res, apiIndex)
},
fail: (res) => {
TestConsole.consoleFail.call(this, res, apiIndex)
},
complete: (res) => {
TestConsole.consoleComplete.call(this, res, apiIndex)
},
})
},
fail: (res) => {
TestConsole.consoleNormal('saveFile fail ', res.errMsg)
},
complete: (res) => {
TestConsole.consoleNormal('saveFile complete ', res)
},
})
},
})
},
},
{
id: 'fileSystem_readFile',
func: (apiIndex) => {
TestConsole.consoleTest('fileSystem_readFile')
Taro.chooseImage({
success: (res) => {
var tempFilePaths = res.tempFilePaths
Taro.saveFile({
tempFilePath: tempFilePaths[0],
filePath: 'D:/common',
success: (res) => {
TestConsole.consoleNormal('saveFile success ', res)
fileSystemManager.readFile({
filePath: res.savedFilePath,
position: 0,
length: 1,
encoding: '',
success: (res) => {
TestConsole.consoleSuccess.call(this, res, apiIndex)
},
fail: (res) => {
TestConsole.consoleFail.call(this, res, apiIndex)
},
complete: (res) => {
TestConsole.consoleComplete.call(this, res, apiIndex)
},
})
},
fail: (res) => {
TestConsole.consoleNormal('saveFile fail ', res.errMsg)
},
complete: (res) => {
TestConsole.consoleNormal('saveFile complete ', res)
},
})
},
})
},
},
{
id: 'fileSystem_readFileSync',
func: (apiIndex) => {
TestConsole.consoleTest('fileSystem_readFileSync')
Taro.chooseImage({
success: (res) => {
var tempFilePaths = res.tempFilePaths
Taro.saveFile({
tempFilePath: tempFilePaths[0],
filePath: 'D:/common',
success: function (sucRes) {
TestConsole.consoleNormal('saveFile success ', sucRes)
str = fileSystemManager.readFileSync({
filePath: sucRes.savedFilePath,
encoding: '',
position: 0,
length: 1,
})
TestConsole.consoleNormal('readFileSync success ', str)
},
fail: function (failRes) {
TestConsole.consoleNormal('saveFile fail ', failRes.errMsg)
},
complete: function (comRes) {
TestConsole.consoleNormal('saveFile complete ', comRes)
},
})
},
})
},
},
],
}
render() {
Expand Down
42 changes: 42 additions & 0 deletions examples/mini-program-example/src/pages/api/media/audio/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const seekedCallback = () => {
TestConsole.consoleNormal('on/offseeked callback')
}
let innercontext
let audioContext
export default class Index extends React.Component {
state = {
list: [
Expand Down Expand Up @@ -275,6 +276,47 @@ export default class Index extends React.Component {
innercontext.offSeeked(seekedCallback)
},
},
{
id: 'createAudioContext',
func: (apiIndex) => {
TestConsole.consoleTest('createAudioContext')
audioContext = Taro.createAudioContext('myAudio')
},
},
{
id: 'audioContext_play',
func: (apiIndex) => {
TestConsole.consoleTest('audioContext_play')
audioContext.play()
},
},
{
id: 'audioContext_pause',
func: (apiIndex) => {
TestConsole.consoleTest('audioContext_pause')
audioContext.pause()
},
},
{
id: 'audioContext_seek',
inputData: {
position: 120,
},
func: (apiIndex, data) => {
TestConsole.consoleTest('audioContext_seek')
audioContext.seek(data.position)
},
},
{
id: 'audioContext_setSrc',
inputData: {
src: 'https://storage.360buyimg.com/jdrd-blog/27.mp3',
},
func: (apiIndex, data) => {
TestConsole.consoleTest('audioContext_setSrc')
audioContext.setSrc(data.src)
},
},
],
}
render() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// null-implementation
export const getExptInfoSync = function () {
return {}
}
5 changes: 3 additions & 2 deletions packages/taro-mpharmony/src/api/data-analysis/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { temporarilyNotSupport } from '../../utils'

export const reportMonitor = /* @__PURE__ */ temporarilyNotSupport('reportMonitor')
export const reportAnalytics = /* @__PURE__ */ temporarilyNotSupport('reportAnalytics')
export const reportEvent = /* @__PURE__ */ temporarilyNotSupport('reportEvent')
export const getExptInfoSync = /* @__PURE__ */ temporarilyNotSupport('getExptInfoSync')

export * from './getExptInfoSync'
export * from './reportAnalytics'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// null-implementation
export const reportAnalytics = function () {}
52 changes: 52 additions & 0 deletions packages/taro-mpharmony/src/api/media/audio/AudioContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Taro from '@tarojs/api'

export class AudioContext implements Taro.AudioContext {
Instance?: HTMLAudioElement

constructor () {
this.Instance = new Audio()

Taro.eventCenter.on('__taroRouterChange', () => {
this.stop()
})
}

get paused () {
return this.Instance?.paused ?? true
}

get src () {
return this.Instance?.src || ''
}

set src (e) {
this.setProperty('src', e)
}

private setProperty (key: string, value: unknown) {
if (this.Instance) {
this.Instance[key] = value
}
}

play = () => this.Instance?.play()

pause = () => this.Instance?.pause()

stop = () => {
this.pause()
this.seek(0)
}

seek = (position: number) => {
if (this.Instance) {
this.Instance.currentTime = position
}
}

setSrc = (src: string) => {
if (this.Instance) {
this.Instance.src = src
}
}
}
3 changes: 2 additions & 1 deletion packages/taro-mpharmony/src/api/media/audio/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Taro from '@tarojs/api'

import { temporarilyNotSupport } from '../../../utils'
import { AudioContext } from './AudioContext'
import { InnerAudioContext } from './InnerAudioContext'

// 音频
Expand All @@ -25,4 +26,4 @@ export const createInnerAudioContext: typeof Taro.createInnerAudioContext = (opt
}
}

export const createAudioContext = /* @__PURE__ */ temporarilyNotSupport('createAudioContext')
export const createAudioContext: typeof Taro.createAudioContext = () => new AudioContext()

0 comments on commit c29e5a6

Please sign in to comment.