-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Farmer app audio support #290
Open
FaithDaka
wants to merge
14
commits into
main
Choose a base branch
from
farmer-app-audio-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2bbe9f1
feat: audio playback service and component
FaithDaka 4ebd7e2
feat: audio playback service
FaithDaka 7968b53
feat: audio playback component
FaithDaka af7ed64
feat: audio service test in farmer app
FaithDaka 39ca7f7
chore: package update
FaithDaka 6eebe4a
Merge branch 'main' into farmer-app-audio-support
FaithDaka f908426
Merge branch 'main' of https://github.com/e-picsa/picsa-apps into far…
chrismclarke 1bdf8cb
chore: code tidying
chrismclarke 04968f0
fix: use if-else statement
FaithDaka f524f58
refactor: use color variable
FaithDaka 79f5547
refactor: audio play logic
FaithDaka 2447ca6
routing
FaithDaka 194febb
style: colour variable
FaithDaka 1b9eb91
Merge branch 'farmer-app-audio-support' of https://github.com/e-picsa…
FaithDaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
libs/shared/src/features/audio-playback/audio-playback.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div (click)="togglePlayback()" class="audio-button"> | ||
@if (isAudioPlaying) { | ||
<button mat-flat-button><mat-icon>play_circle_outline</mat-icon></button> | ||
} @else{ | ||
<button mat-flat-button><mat-icon>headset</mat-icon></button> | ||
} | ||
</div> |
15 changes: 15 additions & 0 deletions
15
libs/shared/src/features/audio-playback/audio-playback.component.scss
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,15 @@ | ||
.audio-button{ | ||
outline: none; | ||
background-color: none; | ||
border: none; | ||
padding: 5px; | ||
&:hover{ | ||
background-color: none; | ||
} | ||
.mat-icon{ | ||
color: var(--color-secondary); | ||
font-size: 28px; | ||
height: 32px; | ||
width: 32px; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
libs/shared/src/features/audio-playback/audio-playback.component.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,21 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { AudioPlaybackComponent } from './audio-playback.component'; | ||
|
||
describe('AudioPlaybackComponent', () => { | ||
let component: AudioPlaybackComponent; | ||
let fixture: ComponentFixture<AudioPlaybackComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [AudioPlaybackComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(AudioPlaybackComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
libs/shared/src/features/audio-playback/audio-playback.component.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,32 @@ | ||
import { Component, OnDestroy, Input } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { AudioService } from './audio-playback.service'; | ||
import { MatIconModule } from '@angular/material/icon'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
|
||
@Component({ | ||
selector: 'picsa-audio-playback', | ||
standalone: true, | ||
imports:[CommonModule, MatIconModule, MatButtonModule], | ||
templateUrl: './audio-playback.component.html', | ||
styleUrls: ['./audio-playback.component.scss'], | ||
}) | ||
export class AudioPlaybackComponent implements OnDestroy { | ||
@Input() audioUrl: string; | ||
isAudioPlaying = false; | ||
|
||
constructor(private audioService: AudioService) {} | ||
|
||
togglePlayback(): void { | ||
this.isAudioPlaying = !this.isAudioPlaying; | ||
if (this.audioService.isPlaying()) { | ||
this.audioService.pauseAudio(); | ||
} else { | ||
this.audioService.playAudio(this.audioUrl); | ||
} | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.audioService.stop(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
libs/shared/src/features/audio-playback/audio-playback.service.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,34 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class AudioService { | ||
private audio: HTMLAudioElement; | ||
|
||
constructor() { | ||
this.audio = new Audio(); | ||
} | ||
|
||
playAudio(url: string): void { | ||
if (this.audio.src !== url) { | ||
this.audio.src = url; | ||
} | ||
this.audio.play(); | ||
} | ||
|
||
pauseAudio(): void { | ||
this.audio.pause(); | ||
} | ||
|
||
isPlaying(): boolean { | ||
return !this.audio.paused; | ||
} | ||
|
||
stop(): void { | ||
if (this.audio) { | ||
this.audio.pause(); | ||
this.audio.currentTime = 0; | ||
} | ||
} | ||
} |
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,2 @@ | ||
export * from './audio-playback.component'; | ||
export * from './audio-playback.service'; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 - nice you were able to do get things working with the standard html audio api. In another project I've used HowlerJS, however it looks like the api should be sufficient for now