Skip to content

Commit

Permalink
Issue 1
Browse files Browse the repository at this point in the history
Ahora no se cargan los archivos que ya estén cargados.
  • Loading branch information
nonodev96 committed Mar 11, 2019
1 parent fefb0ca commit a3f9252
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 34 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.0.6 (2019-03-11)

* fix/ eliminado el bug que duplicaba las canciones.
* Se han añadido funciones de matematica discreta para trabajar con arrays.

## 0.0.5 (2019-03-10)

* fix/ variable isPlaying de component-song eliminada y ahora funciona con el observable.

## 0.0.4 (2019-03-10)

* fix/ song cassette with observables audio and song for play and paused
* fix/ song cassette con observables audio.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "muse-ujaen",
"version": "0.0.5",
"version": "0.0.6",
"description": "Angular 7 with Electron (Typescript + SASS + Hot Reload)",
"homepage": "https://github.com/nonodev96/muse",
"author": {
Expand Down Expand Up @@ -41,7 +41,6 @@
"@angular/animations": "^7.2.5",
"@angular/cdk": "^7.3.2",
"@angular/material": "^7.3.2",
"electron-json-storage": "^4.1.6",
"music-metadata": "^3.5.2",
"music-metadata-browser": "^0.7.1"
},
Expand Down
93 changes: 64 additions & 29 deletions src/app/providers/player.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { Song } from '../mock/Song';
import { FileService } from './file.service';
import { IAudioMetadata } from 'music-metadata/lib/type';
import { ElectronService } from './electron.service';
import { forEach } from '@angular/router/src/utils/collection';
import { iterator } from 'rxjs/internal-compatibility';
import {Injectable} from '@angular/core';
import {Observable, Subject} from 'rxjs';
import {Song} from '../mock/Song';
import {FileService} from './file.service';
import {IAudioMetadata} from 'music-metadata/lib/type';
import {ElectronService} from './electron.service';


@Injectable({
Expand All @@ -23,6 +21,7 @@ export class PlayerService {
private currentTimeObservable = new Subject<number>();
private durationTimeObservable = new Subject<number>();
private elapsedTimeObservable = new Subject<number>();
private musicFiles: string[] = [];

constructor(private _fileService: FileService, private _electronService: ElectronService) {
this.song = new Song();
Expand Down Expand Up @@ -90,7 +89,7 @@ export class PlayerService {
if (this.iterator >= this.songList.length) {
this.iterator = 0;
}
let song: Song = this.songList[ this.iterator ];
let song: Song = this.songList[this.iterator];
this.setSong(song);
}

Expand Down Expand Up @@ -142,41 +141,77 @@ export class PlayerService {
return data;
}

private initPlayerFromMusicFiles(musicFiles) {
console.log({ ...musicFiles });
private initPlayerFromMusicFiles(musicFiles: string[]) {
let differenceMusicFiles: string[] = <string[]>Array.from(this.setDifference(new Set(musicFiles), new Set(this.musicFiles)));
this.musicFiles = <string[]>Array.from(this.setUnion(new Set(this.musicFiles), new Set(musicFiles)));
console.log(differenceMusicFiles);

let title, album, artist, data_song;
for (let pathFile of musicFiles) {
for (let index in differenceMusicFiles) {
let pathFile: string = differenceMusicFiles[index];
this._fileService.loadAudioMetaDataFromPath(pathFile).then(
(value: IAudioMetadata) => {

data_song = value;
title = value.common.title;
album = value.common.album;
artist = value.common.artist;
let addToList = new Song({
id: pathFile.index,
title: title,
album: album,
artist: artist,
(audioMetadataValue: IAudioMetadata) => {
this.songList.push(new Song({
id: '1',
title: audioMetadataValue.common.title,
album: audioMetadataValue.common.album,
artist: audioMetadataValue.common.artist,
src: pathFile,
audioMetadata: data_song
});
this.songList.push(addToList);
audioMetadata: audioMetadataValue
}));
this.songListObservable.next(this.songList);
this.songListObservable.complete();
});
}
}

private ipcRendererSelectedFiles() {
this._electronService.ipcRenderer.on('selected-files', (event, args) => {
if (args.musicFiles.length > 0) {
this.initPlayerFromMusicFiles(args.musicFiles);
let arrayMusicFiles: string[] = [...args.musicFiles];
this.initPlayerFromMusicFiles(arrayMusicFiles);
}
});
}

private toConsumableArray(arr): any {
return this.arrayWithoutHoles(arr) || this.iterableToArray(arr) || this.nonIterableSpread();
}

private nonIterableSpread() {
throw new TypeError('Invalid attempt to spread non-iterable instance');
}

private iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === '[object Arguments]') {
return Array.from(iter);
}
}

private arrayWithoutHoles(arr) {
if (Array.isArray(arr)) {
let arr2 = new Array(arr.length);
for (let i = 0; i < arr.length; i++) {
arr2[i] = arr[i];
}
return arr2;
}
}

private setDifference(a, b) {
return new Set(this.toConsumableArray(a).filter(function (x) {
return !b.has(x);
}));
}

private setIntersection(a, b) {
return new Set(this.toConsumableArray(a).filter(function (x) {
return b.has(x);
}));
}

private setUnion(a, b) {
return new Set([].concat(this.toConsumableArray(a), this.toConsumableArray(b)));
}

private debug() {
console.log(this.getData());
}
Expand Down
4 changes: 2 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<html>
<head>
<meta charset="utf-8">
<title>AngularElectron</title>
<title>Muse uJaén</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<base href="">

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root>Loading...</app-root>
<app-root>Loading...</app-root>
</body>
</html>

0 comments on commit a3f9252

Please sign in to comment.