-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #717 from videogular/feat/quality-switcher
feat(controls): Add quality switcher
- Loading branch information
Showing
5 changed files
with
257 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/controls/vg-quality-selector/vg-quality-selector.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { VgQualitySelector } from "./vg-quality-selector"; | ||
import { VgAPI } from "../../core/services/vg-api"; | ||
import { ElementRef } from "@angular/core"; | ||
|
||
describe('Quality Selector control', () => { | ||
let vgQualitySelector: VgQualitySelector; | ||
|
||
beforeEach(() => { | ||
const ref: ElementRef = { | ||
nativeElement: { | ||
getAttribute: (name) => { | ||
return name; | ||
} | ||
} | ||
}; | ||
vgQualitySelector = new VgQualitySelector(ref, new VgAPI()); | ||
}); | ||
|
||
describe('onPlayerReady', () => { | ||
|
||
}); | ||
}); |
142 changes: 142 additions & 0 deletions
142
src/controls/vg-quality-selector/vg-quality-selector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import { | ||
Component, | ||
ElementRef, | ||
OnInit, | ||
Input, | ||
ViewEncapsulation, | ||
OnDestroy, | ||
SimpleChanges, | ||
OnChanges, Output, EventEmitter | ||
} from '@angular/core'; | ||
import { VgAPI } from '../../core/services/vg-api'; | ||
import { Subscription } from 'rxjs/Subscription'; | ||
import { BitrateOption } from '../../core/core'; | ||
|
||
@Component({ | ||
selector: 'vg-quality-selector', | ||
encapsulation: ViewEncapsulation.None, | ||
template: ` | ||
<div class="container"> | ||
<div class="quality-selected" | ||
[class.vg-icon-closed_caption]="!bitrateSelected"> | ||
{{ bitrateSelected?.label }} | ||
</div> | ||
<select class="quality-selector" | ||
(change)="selectBitrate($event.target.value)" | ||
tabindex="0" | ||
aria-label="quality selector" | ||
[attr.aria-valuetext]="ariaValue"> | ||
<option | ||
*ngFor="let bitrate of bitrates" | ||
[value]="bitrate.qualityIndex" | ||
[selected]="bitrate.qualityIndex === bitrateSelected.qualityIndex"> | ||
{{ bitrate.label }} | ||
</option> | ||
</select> | ||
</div> | ||
`, | ||
styles: [ ` | ||
vg-quality-selector { | ||
-webkit-touch-callout: none; | ||
-webkit-user-select: none; | ||
-moz-user-select: none; | ||
-ms-user-select: none; | ||
user-select: none; | ||
display: flex; | ||
justify-content: center; | ||
width: 50px; | ||
height: 50px; | ||
cursor: pointer; | ||
color: white; | ||
line-height: 50px; | ||
} | ||
vg-quality-selector .container { | ||
position: relative; | ||
display: flex; | ||
flex-grow: 1; | ||
align-items: center; | ||
padding: 0; | ||
margin: 5px; | ||
} | ||
vg-quality-selector select.quality-selector { | ||
width: 50px; | ||
padding: 5px 8px; | ||
border: none; | ||
background: none; | ||
-webkit-appearance: none; | ||
-moz-appearance: none; | ||
appearance: none; | ||
color: transparent; | ||
font-size: 16px; | ||
} | ||
vg-quality-selector select.quality-selector::-ms-expand { | ||
display: none; | ||
} | ||
vg-quality-selector select.quality-selector option { | ||
color: #000; | ||
} | ||
vg-quality-selector .quality-selected { | ||
position: absolute; | ||
width: 100%; | ||
height: 50px; | ||
top: -6px; | ||
text-align: center; | ||
text-transform: uppercase; | ||
font-family: Helvetica Neue, Helvetica, Arial, sans-serif; | ||
padding-top: 2px; | ||
pointer-events: none; | ||
} | ||
vg-quality-selector .vg-icon-closed_caption:before { | ||
width: 100%; | ||
} | ||
` ] | ||
}) | ||
export class VgQualitySelector implements OnInit, OnChanges, OnDestroy { | ||
@Input() vgFor: string; | ||
@Input() bitrates: BitrateOption[]; | ||
|
||
@Output() onBitrateChange: EventEmitter<BitrateOption> = new EventEmitter(); | ||
|
||
bitrateSelected: BitrateOption; | ||
|
||
elem: HTMLElement; | ||
target: any; | ||
|
||
subscriptions: Subscription[] = []; | ||
|
||
ariaValue: string; | ||
|
||
constructor(ref: ElementRef, public API: VgAPI) { | ||
this.elem = ref.nativeElement; | ||
} | ||
|
||
ngOnInit() { | ||
if (this.API.isPlayerReady) { | ||
this.onPlayerReady(); | ||
} | ||
else { | ||
this.subscriptions.push(this.API.playerReadyEvent.subscribe(() => this.onPlayerReady())); | ||
} | ||
} | ||
|
||
ngOnChanges(changes: SimpleChanges) { | ||
if (changes['bitrates'].currentValue && changes['bitrates'].currentValue.length) { | ||
this.bitrates.forEach(item => item.label = item.label || Math.round(item.bitrate / 1000).toString()) | ||
} | ||
} | ||
|
||
onPlayerReady() { | ||
this.target = this.API.getMediaById(this.vgFor); | ||
} | ||
|
||
selectBitrate(index: number) { | ||
this.bitrateSelected = this.bitrates[index]; | ||
this.onBitrateChange.emit(this.bitrates[index]); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.subscriptions.forEach(s => s.unsubscribe()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters