Skip to content

Commit

Permalink
Start blablab stream when stream is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-battaglia committed Oct 30, 2024
1 parent 5e87f1f commit ed3b8c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</mat-card-header>
<mat-card-content>
<div>
<audio id="player" #player></audio>
<audio id="player" (canplay)="startPlayBack()" #player></audio>
<mat-form-field appearance="outline" subscriptSizing="dynamic">
<mat-label>Sender</mat-label>
<mat-select [(value)]="selectedStation">
Expand Down
18 changes: 12 additions & 6 deletions blablaspotify_frontend/src/app/blabla/player/player.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class PlayerComponent {

private _radioStationFacade = inject(RadioStationFacade)

protected readonly playerElement = viewChild<ElementRef>('player')
protected readonly playerElement = viewChild<ElementRef<HTMLAudioElement>>('player')

protected readonly selectedStation = model<string>(this._radioStationFacade.stations()[0].epgId)

Expand All @@ -42,18 +42,24 @@ export class PlayerComponent {
const stationUrl = this.stationUrl()

untracked(() => {
const player = this.playerElement()?.nativeElement as HTMLAudioElement
player.src = stationUrl
const player = this.playerElement()?.nativeElement
player!.src = stationUrl

if (isPlaying) {
player.load()
player.play()
player!.load()
//player.play()
} else {
player.pause()
player!.pause()
}
})
})

protected startPlayBack() {
if (this.isActive()) {
this.playerElement()!.nativeElement.play()
}
}

private getStreamUrl(epgId?: string) {
const station = this._radioStationFacade.stations().find(station => station.epgId === epgId)
return station === undefined ? '' : station.streamUrl
Expand Down

0 comments on commit ed3b8c1

Please sign in to comment.