Changeset 35409 for main


Ignore:
Timestamp:
2021-09-16T10:27:17+12:00 (3 years ago)
Author:
cstephen
Message:

Refactor to use state-based audio playback

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/App.vue

    r35408 r35409  
    1414        <transition-group name="transcription-list">
    1515            <li class="list-item transcription-list-item" v-for="[id, transcription] in transcriptions" :key="id">
    16                 <TranscriptionItem :transcription="transcription" @playAudio="playAudio($event)" />
     16                <TranscriptionItem :transcription="transcription" />
    1717            </li>
    1818        </transition-group>
     
    8282        translations: state => state.translations,
    8383        transcriptions: state => state.rawTranscriptions,
    84         playbackState: state => state.playbackState
     84        playbackState: state => state.playbackState,
     85        shouldPlayAudio: state => state.playbackState.isPlaying
    8586    }),
    86     methods: {
    87         /**
    88          * Plays transcription audio.
    89          * @param {{id: String, time: Number}} event The playback request event.
    90          */
    91         playAudio(event) {
    92             const transcription = this.transcriptions.get(event.id);
     87    watch: {
     88        playbackState(newValue) {
     89            if (!newValue.isPlaying) {
     90                return;
     91            }
     92
     93            const transcription = this.transcriptions.get(newValue.id);
    9394            loadTranscriptionAudio(this.$refs.audioPlayer, this.$refs.audioPlayerSource, transcription, this.currentlyLoadedAudio);
    9495
    95             if (event.time < 0) {
    96                 event.time = 0;
     96            let playbackTime = 0;
     97            if (newValue.currentTime > 0) {
     98                playbackTime = newValue.currentTime;
    9799            }
    98100
    99             this.$store.commit("setCurrentlyPlayingId", event.id);
    100 
    101             this.$refs.audioPlayer.currentTime = event.time;
     101            this.$refs.audioPlayer.currentTime = playbackTime;
    102102            this.$refs.audioPlayer.play();
    103         }
    104     },
    105     watch: {
    106         playbackState(newValue) {
    107             console.log("Playback state changed.");
    108         }
     103        }//,
     104        // shouldPlayAudio(newValue) {
     105        //     if (newValue && this.$refs.audioPlayer.paused) {
     106        //         this.$refs.audioPlayer.play();
     107        //     }
     108        //     else if (!newValue && !this.$refs.audioPlayer.paused) {
     109        //         this.$refs.audioPlayer.pause();
     110        //     }
     111        // }
    109112    },
    110113    mounted() {
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/TranscriptionItem.vue

    r35406 r35409  
    33        <!-- Header containing info and actions for the transcription -->
    44        <div class="transcription__header">
    5             <button class="btn-fab" v-on:click="playAudio(0)" type="button">
     5            <button class="btn-fab" v-on:click="playAudio" type="button">
    66                <span class="material-icons mdi-l">play_arrow</span>
    77            </button>
     
    4040        </div>
    4141
    42         <TranscriptionItemEditor :transcription="transcription" @playAudio="playAudio($event)" />
     42        <TranscriptionItemEditor :transcription="transcription" />
    4343
    4444        <hr />
     
    9696import { saveAs } from "file-saver"
    9797import TranscriptionItemEditor, { getWords } from "./TranscriptionItemEditor.vue"
    98 import { TranscriptionViewModel } from "../main";
     98import { TranscriptionViewModel, PlaybackState } from "../main";
    9999
    100100export default {
     
    106106        transcription: TranscriptionViewModel
    107107    },
    108     emits: [ "playAudio" ],
    109108    data() {
    110109        return {
     
    121120        },
    122121        playAudio(startTime = 0) {
    123             this.$emit("playAudio", { id: this.transcription.id, time: startTime });
     122            const pState = new PlaybackState(this.transcription.id, true, startTime);
     123            this.$store.commit("setPlaybackState", pState);
    124124        },
    125125        remove() {
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/TranscriptionItemEditor.vue

    r35408 r35409  
    7676<script>
    7777import { mapState } from "vuex";
    78 import { TranscriptionViewModel } from "../main";
     78import { TranscriptionViewModel, PlaybackState } from "../main";
    7979import Util from "../js/Util";
    8080
     
    119119        }
    120120    },
    121     emits: [ "playAudio" ],
    122121    computed: mapState({
    123122        playbackState: state => state.playbackState,
     
    127126    methods: {
    128127        playAudio(startTime) {
    129             this.$emit("playAudio", startTime);
     128            const pState = new PlaybackState(this.transcription.id, true, startTime);
     129            this.$store.commit("setPlaybackState", pState);
    130130        },
    131131        /**
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/main.js

    r35408 r35409  
    3030
    3131export class PlaybackState {
    32     constructor() {
     32    /**
     33     * Initialises a new instance of the {@link PlaybackState} class.
     34     * @param {String} id The ID of the transcription for which audio is being played.
     35     * @param {Boolean} isPlaying A value indicating if audio is currently being played.
     36     * @param {Numbe} currentTime The current time in the audio playback.
     37     */
     38    constructor(id = "", isPlaying = false, currentTime = -1) {
    3339        /** @type {String} The ID of the transcription for which audio is currently being played. */
    34         this.id = "";
     40        this.id = id;
    3541
    3642        /** @type {Boolean} Gets a value indicating if audio is currently being played back. */
    37         this.isPlaying = false;
     43        this.isPlaying = isPlaying;
    3844
    3945        /** @type {Number} Gets the current time in the playback. */
    40         this.currentTime = -1;
     46        this.currentTime = currentTime;
    4147    }
    4248}
Note: See TracChangeset for help on using the changeset viewer.