Changeset 35450


Ignore:
Timestamp:
2021-09-22T14:03:14+12:00 (3 years ago)
Author:
cstephen
Message:

Keep playback state when switching audio tracks

Location:
main/trunk/model-interfaces-dev/atea/korero-maori-asr/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/AudioTimeBar.vue

    r35430 r35450  
    11<template>
    22<div class="root">
    3     <input type="range" class="slider-continuous" v-model.number="sliderValue" :max="audioLength" step="0.01" :disabled="isDisabled" />
     3    <input type="range" class="slider-continuous" v-model.number="sliderValue" min="0" :max="audioLength" step="0.01" :disabled="isDisabled" />
    44    <span>{{ stringSliderValue }}</span>
    55</div>
     
    2828        sliderValue: {
    2929            get() {
    30                 if (this.modelValue < 0 || this.isDisabled) {
    31                     return 0;
    32                 }
    33 
    3430                if (this.modelValue > this.audioLength) {
    3531                    return this.audioLength;
    3632                }
    37 
    38                 return this.modelValue;
     33                else if (this.modelValue < 0) {
     34                    return 0;
     35                }
     36                else {
     37                    return this.modelValue;
     38                }
    3939            },
    4040            set(newValue) {
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/TranscriptionItemEditor.vue

    r35449 r35450  
    2121
    2222    <div class="editor-controls">
    23         <audio-time-bar v-model.number="currentPlaybackTime" :audio-length="playbackState.length" :isDisabled="playbackState.id != transcription.id" />
     23        <audio-time-bar v-model.number="currentPlaybackTime" :audio-length="audioLength" :isDisabled="playbackState.id != transcription.id" />
    2424
    2525        <toggle-button v-model="enableEditing" title="Toggle Edit Mode">
     
    129129        currentPlaybackTime: {
    130130            get() {
    131                 return this.$store.state.playbackState.currentTime;
     131                return this.$store.getters.transcriptionPlaybackTime(this.transcription.id);
    132132            },
    133133            set(value) {
    134                 this.$store.commit("playbackStateSetCurrentTime", value);
    135             }
     134                this.$store.commit("playbackStateSetTime", { id: this.transcription.id, time: value });
     135            }
     136        },
     137        audioLength() {
     138            return this.$store.getters.transcriptionPlaybackLength(this.transcription.id);
    136139        },
    137140        ...mapState({
     
    169172        onEditorFocus(index) {
    170173            const wordStartTime = this.words[index].startTime + 0.01;
    171             this.$store.commit("playbackStateSetCurrentTime", wordStartTime);
     174            this.$store.commit("playbackStateSetTime", { id: this.transcription.id, time: wordStartTime });
    172175        },
    173176        onEditorFocusOut(index) {
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/js/AudioPlaybackModule.js

    r35446 r35450  
    3232        if (audioElement.currentTime !== lastTime) {
    3333            lastTime = audioElement.currentTime;
    34             store.commit("playbackStateSetCurrentTime", lastTime);
     34            store.commit("playbackStateSetTime", { id: store.state.playbackState.id, time: lastTime });
    3535        }
    3636
     
    8484     */
    8585    static async play(id, startTime = -1) {
    86         const playbackState = this.store.state.playbackState;
     86        const playbackTimes = this.store.state.playbackState.playbackTimes;
    8787
    8888        let playbackTime = startTime;
    89         if (playbackState.id === id && startTime < 0) {
    90             playbackTime = playbackState.currentTime;
     89        if (playbackTimes.has(id) && startTime < 0) {
     90            playbackTime = playbackTimes.get(id);
    9191        }
    9292
     
    100100        await this.player.play();
    101101
    102         this.store.commit("playbackStateSetLength", this.player.duration);
     102        this.store.commit("playbackStateSetLength", { id: id, time: this.player.duration });
    103103        this.store.commit("playbackStateSetIsPlaying", true);
    104104    }
    105105
     106    /**
     107     * Pauses playback.
     108     */
    106109    static pause() {
    107110        this.player.pause();
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/main.js

    r35446 r35450  
    4242     * @param {Number} length The length of the audio track.
    4343     */
    44     constructor(id = "", isPlaying = false, currentTime = 0, length = 0) {
     44    constructor(id = "", isPlaying = false, length = 0) {
    4545        /** @type {String} The ID of the transcription for which audio is currently being played. */
    4646        this.id = id;
     
    4949        this.isPlaying = isPlaying;
    5050
    51         /** @type {Number} Gets the current time in the playback. */
    52         this.currentTime = currentTime;
     51        /** @type {Map<String, Number} The current playback time of each transcription's audio. */
     52        this.playbackTimes = new Map();
    5353
    54         /** @type {Number} Gets the length of the current audio track. */
    55         this.length = length;
     54        /** @type {Map<String, Number} The length of each transcription's audio. */
     55        this.playbackLengths = new Map();
    5656    }
    5757}
     
    101101            state.playbackState.isPlaying = isPlaying;
    102102        },
    103         playbackStateSetCurrentTime(state, time) {
    104             state.playbackState.currentTime = time;
     103        playbackStateSetTime(state, object) {
     104            state.playbackState.playbackTimes.set(object.id, object.time);
    105105        },
    106         playbackStateSetLength(state, length) {
    107             state.playbackState.length = length;
     106        playbackStateSetLength(state, object) {
     107            state.playbackState.playbackLengths.set(object.id, object.time);
    108108        },
    109109
     
    116116            const id = TranscriptionViewModel.getId(file);
    117117            return state.rawTranscriptions.has(id);
     118        },
     119        transcriptionPlaybackTime: (state) => (id) => {
     120            return state.playbackState.playbackTimes.has(id) ? state.playbackState.playbackTimes.get(id) : 0;
     121        },
     122        transcriptionPlaybackLength: (state) => (id) => {
     123            return state.playbackState.playbackLengths.has(id) ? state.playbackState.playbackLengths.get(id) : 0;
    118124        }
    119125    }
Note: See TracChangeset for help on using the changeset viewer.