TT#69459 Fix media initialisation in CscMedia component

Change-Id: Ifc54b9851716a8b42d13adb5e842847c5c683b15
changes/64/34664/1
Hans-Peter Herzog 6 years ago
parent 5d930a509b
commit b9bb89d765

@ -23,7 +23,7 @@
:muted="muted" :muted="muted"
@click="fitMedia" @click="fitMedia"
@resize="fitMedia" @resize="fitMedia"
/> ></video>
</div> </div>
</template> </template>
@ -43,7 +43,7 @@
], ],
data () { data () {
return { return {
currentStream: this.stream, currentStream: null,
loading: true, loading: true,
mediaHeight: 0, mediaHeight: 0,
mediaWidth: 0, mediaWidth: 0,
@ -52,6 +52,7 @@
} }
}, },
mounted () { mounted () {
this.assignStream(this.stream);
let fitMedia = ()=>{ this.fitMedia(); }; let fitMedia = ()=>{ this.fitMedia(); };
this.$root.$on('window-resized', fitMedia); this.$root.$on('window-resized', fitMedia);
this.$root.$on('content-resized', fitMedia); this.$root.$on('content-resized', fitMedia);
@ -63,6 +64,8 @@
}, },
methods: { methods: {
assignStream(stream) { assignStream(stream) {
if(stream !== this.currentStream && stream !== null && stream !== undefined) {
this.loading = true;
this.currentStream = stream; this.currentStream = stream;
if(_.isObject(this.currentStream) && _.isObject(this.$refs.media) && if(_.isObject(this.currentStream) && _.isObject(this.$refs.media) &&
!_.isUndefined(this.$refs.media.srcObject)) { !_.isUndefined(this.$refs.media.srcObject)) {
@ -77,13 +80,27 @@
this.$refs.media.src = URL.createObjectURL(this.currentStream); this.$refs.media.src = URL.createObjectURL(this.currentStream);
} }
let timer = setInterval(()=>{ let timer = setInterval(()=>{
if(this.currentStream !== null && (this.$refs.media.currentTime > 0 || if(this.currentStream !== null && (this.$refs.media && (this.$refs.media.currentTime > 0 ||
this.$refs.media.readyState > 2)) { this.$refs.media.readyState > 2))) {
this.loading = false; this.loading = false;
clearInterval(timer); clearInterval(timer);
this.fitMedia(); this.fitMedia();
} }
}, 100); }, 100);
}
else {
this.loading = false;
this.currentStream = null;
if(this.$refs.media.srcObject) {
this.$refs.media.srcObject = null;
}
else if(this.$refs.media.mozSrcObject) {
this.$refs.media.mozSrcObject = null;
}
else {
this.$refs.media.src = null;
}
}
}, },
fitMediaToParent() { fitMediaToParent() {
if(this.$refs.media && this.$refs.media && if(this.$refs.media && this.$refs.media &&
@ -163,22 +180,7 @@
}, },
watch: { watch: {
stream(stream) { stream(stream) {
if(stream !== null && stream !== this.currentStream) {
this.loading = true;
this.assignStream(stream); this.assignStream(stream);
}
else {
this.currentStream = null;
if(this.$refs.media.srcObject) {
this.$refs.media.srcObject = null;
}
else if(this.$refs.media.mozSrcObject) {
this.$refs.media.mozSrcObject = null;
}
else {
this.$refs.media.src = null;
}
}
}, },
muted(muted) { muted(muted) {
this.$refs.media.muted = muted; this.$refs.media.muted = muted;

Loading…
Cancel
Save