-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add play and pause functionality with a demo mp3
- Loading branch information
Showing
6 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
17 changes: 10 additions & 7 deletions
17
app/src/app/apps/app/player/controls/controls.component.html
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
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
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,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { PlayerService } from './player.service'; | ||
|
||
describe('PlayerService', () => { | ||
let service: PlayerService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(PlayerService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
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,52 @@ | ||
import { Injectable, signal } from '@angular/core'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class PlayerService { | ||
title = signal<string>(''); | ||
|
||
audio?: HTMLAudioElement; | ||
|
||
constructor() {} | ||
|
||
previous() {} | ||
|
||
next() {} | ||
|
||
async play() { | ||
const url = 'https://file-examples.com/storage/fefcab211666f32e693a865/2017/11/file_example_MP3_700KB.mp3'; | ||
this.setTitle(url); | ||
|
||
if (!this.audio) { | ||
this.audio = new Audio(url); | ||
} | ||
|
||
await this.audio.play(); | ||
} | ||
|
||
setTitle(url: string) { | ||
const parsedUrl = new URL(url); | ||
const pathname = parsedUrl.pathname; | ||
const filename = pathname.substring(pathname.lastIndexOf('/') + 1); | ||
this.title = signal<string>(filename); | ||
} | ||
|
||
pause() { | ||
if (this.audio) { | ||
this.audio.pause(); | ||
} | ||
} | ||
|
||
get paused() { | ||
// if (this.videoMode) { | ||
// return this.youtubeUrl == null; | ||
// } else { | ||
if (!this.audio) { | ||
return true; | ||
} | ||
|
||
return this.audio.paused; | ||
// } | ||
} | ||
} |