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

@@ -10,6 +10,7 @@ export interface IMedia {
title: string;
src: string;
type: string;
label: string;
}
@Component({
@@ -77,10 +78,20 @@ export class PlayerComponent implements OnInit {
const fileName = this.fileNames[i];
const baseLocation = (this.type === 'audio') ? this.audioFolderPath : this.videoFolderPath;
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 = {
title: fileName,
src: fullLocation,
type: fileType
type: fileType,
label: label
}
this.playlist.push(mediaObject);
}