Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
1.修复mute事件bug
2.添加volume事件
  • Loading branch information
bosscheng committed Apr 15, 2024
1 parent 7d57e91 commit 797d577
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 241 deletions.
10 changes: 10 additions & 0 deletions demo/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,16 @@ jessibuca.on("mute", function (flag) {
})
```

### volume

触发音量事件,返回音量值

```js
jessibuca.on("volume", function (volume) {
console.log('volume', volume)
})
```

### stats

流状态统计,流开始播放后回调,每秒1次。
Expand Down
2 changes: 1 addition & 1 deletion demo/public/decoder.js.map

Large diffs are not rendered by default.

Binary file modified demo/public/dist.zip
Binary file not shown.
39 changes: 28 additions & 11 deletions demo/public/jessibuca.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion demo/public/jessibuca.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jessibuca.js

Large diffs are not rendered by default.

26 changes: 20 additions & 6 deletions src/audio/audioContextLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default class AudioContextLoader extends Emitter {
this.audioEnabled(true);
// default setting 0
this.gainNode.gain.value = 0;
this._prevVolume = null;

this.playing = false;
//
Expand Down Expand Up @@ -89,6 +90,7 @@ export default class AudioContextLoader extends Emitter {
this.audioSyncVideoOption = {
diff: null
};
this._prevVolume = null;
this.off();
this.player.debug.log('AudioContext', 'destroy');
}
Expand Down Expand Up @@ -204,15 +206,15 @@ export default class AudioContextLoader extends Emitter {

mute(flag) {
if (flag) {
if (!this.isMute) {
this.player.emit(EVENTS.mute, flag);
}
// if (!this.isMute) {
// this.player.emit(EVENTS.mute, flag);
// }
this.setVolume(0);
this.clear();
} else {
if (this.isMute) {
this.player.emit(EVENTS.mute, flag);
}
// if (this.isMute) {
// this.player.emit(EVENTS.mute, flag);
// }
this.setVolume(0.5);
}
}
Expand All @@ -224,9 +226,21 @@ export default class AudioContextLoader extends Emitter {
}
this.audioEnabled(true);
volume = clamp(volume, 0, 1);
if (this._prevVolume === null) {
this.player.emit(EVENTS.mute, volume === 0);
} else {
if (this._prevVolume === 0 && volume > 0) {
this.player.emit(EVENTS.mute, false);
} else if (this._prevVolume > 0 && volume === 0) {
this.player.emit(EVENTS.mute, true);
}
}
this.gainNode.gain.value = volume;
this.gainNode.gain.setValueAtTime(volume, this.audioContext.currentTime);
this.player.emit(EVENTS.volumechange, this.player.volume);
this.player.emit(EVENTS.volume, this.player.volume); // outer
// save last volume
this._prevVolume = volume;
}

closeAudio() {
Expand Down
44 changes: 0 additions & 44 deletions src/audio/audioLoader.js

This file was deleted.

1 change: 0 additions & 1 deletion src/audio/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import AudioContextLoader from "./audioContextLoader";
import AudioLoader from "./audioLoader";

export default class Audio {
constructor(player) {
Expand Down
4 changes: 0 additions & 4 deletions src/audio/mseAudioLoader.js

This file was deleted.

4 changes: 3 additions & 1 deletion src/constant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const EVENTS = {
streamMessage: 'streamMessage',
streamError: 'streamError',
volumechange: 'volumechange',
volume: 'volume',
destroy: 'destroy',
mseSourceOpen: 'mseSourceOpen',
mseSourceClose: 'mseSourceClose',
Expand Down Expand Up @@ -184,7 +185,8 @@ export const JESSIBUCA_EVENTS = {
recordingTimestamp: EVENTS.recordingTimestamp,
recordStart: EVENTS.recordStart,
recordEnd: EVENTS.recordEnd,
playToRenderTimes: EVENTS.playToRenderTimes
playToRenderTimes: EVENTS.playToRenderTimes,
volume: EVENTS.volume
}

export const EVENTS_ERROR = {
Expand Down
Loading

0 comments on commit 797d577

Please sign in to comment.