fixed bug where playlist titles included their relative path

This commit is contained in:
Isaac Grynsztein
2020-02-29 03:08:02 -05:00
parent a1ac1e450d
commit b87a9f1e2f
2 changed files with 13 additions and 2 deletions

View File

@@ -9,7 +9,7 @@
</div> </div>
<div class="col-12 my-2"> <div class="col-12 my-2">
<mat-button-toggle-group cdkDropList [cdkDropListSortingDisabled]="!id" (cdkDropListDropped)="drop($event)" style="width: 80%; left: 9%" vertical name="videoSelect" aria-label="Video Select" #group="matButtonToggleGroup"> <mat-button-toggle-group cdkDropList [cdkDropListSortingDisabled]="!id" (cdkDropListDropped)="drop($event)" style="width: 80%; left: 9%" vertical name="videoSelect" aria-label="Video Select" #group="matButtonToggleGroup">
<mat-button-toggle cdkDrag *ngFor="let playlist_item of playlist; let i = index" [checked]="currentItem.title === playlist_item.title" (click)="onClickPlaylistItem(playlist_item, i)" class="toggle-button" [value]="playlist_item.title">{{decodeURI(playlist_item.title)}}</mat-button-toggle> <mat-button-toggle cdkDrag *ngFor="let playlist_item of playlist; let i = index" [checked]="currentItem.title === playlist_item.title" (click)="onClickPlaylistItem(playlist_item, i)" class="toggle-button" [value]="playlist_item.title">{{playlist_item.label}}</mat-button-toggle>
</mat-button-toggle-group> </mat-button-toggle-group>
</div> </div>
</div> </div>

View File

@@ -10,6 +10,7 @@ export interface IMedia {
title: string; title: string;
src: string; src: string;
type: string; type: string;
label: string;
} }
@Component({ @Component({
@@ -77,10 +78,20 @@ export class PlayerComponent implements OnInit {
const fileName = this.fileNames[i]; const fileName = this.fileNames[i];
const baseLocation = (this.type === 'audio') ? this.audioFolderPath : this.videoFolderPath; const baseLocation = (this.type === 'audio') ? this.audioFolderPath : this.videoFolderPath;
const fullLocation = this.baseStreamPath + baseLocation + encodeURI(fileName); // + (this.type === 'audio' ? '.mp3' : '.mp4'); const fullLocation = this.baseStreamPath + baseLocation + encodeURI(fileName); // + (this.type === 'audio' ? '.mp3' : '.mp4');
// if it has a slash (meaning it's in a directory), only get the file name for the label
let label = null;
const decodedName = decodeURIComponent(fileName);
const hasSlash = decodedName.includes('/') || decodedName.includes('\\');
if (hasSlash) {
label = decodedName.replace(/^.*[\\\/]/, '');
} else {
label = decodedName;
}
const mediaObject: IMedia = { const mediaObject: IMedia = {
title: fileName, title: fileName,
src: fullLocation, src: fullLocation,
type: fileType type: fileType,
label: label
} }
this.playlist.push(mediaObject); this.playlist.push(mediaObject);
} }