Skip to content

Commit

Permalink
Fixes #490: [Bug] Queue broken
Browse files Browse the repository at this point in the history
  • Loading branch information
digimezzo committed Nov 17, 2023
1 parent 6c7e200 commit 7cbaec7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
16 changes: 10 additions & 6 deletions src/app/services/playback/playback.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ describe('PlaybackService', () => {
// Arrange
const service: PlaybackServiceBase = createService();

while (service.isShuffled !== false) {
while (service.isShuffled) {
service.toggleIsShuffled();
}

Expand All @@ -627,7 +627,7 @@ describe('PlaybackService', () => {
// Arrange
const service: PlaybackServiceBase = createService();

while (service.isShuffled !== false) {
while (service.isShuffled) {
service.toggleIsShuffled();
}

Expand All @@ -642,7 +642,7 @@ describe('PlaybackService', () => {
// Arrange
const service: PlaybackServiceBase = createService();

while (service.isShuffled !== false) {
while (service.isShuffled) {
service.toggleIsShuffled();
}

Expand All @@ -657,7 +657,7 @@ describe('PlaybackService', () => {
// Arrange
const service: PlaybackServiceBase = createService();

while (service.isShuffled !== true) {
while (!service.isShuffled) {
service.toggleIsShuffled();
}

Expand All @@ -672,7 +672,7 @@ describe('PlaybackService', () => {
// Arrange
const service: PlaybackServiceBase = createService();

while (service.isShuffled !== true) {
while (!service.isShuffled) {
service.toggleIsShuffled();
}

Expand All @@ -687,7 +687,7 @@ describe('PlaybackService', () => {
// Arrange
const service: PlaybackServiceBase = createService();

while (service.isShuffled !== true) {
while (!service.isShuffled) {
service.toggleIsShuffled();
}

Expand Down Expand Up @@ -831,6 +831,7 @@ describe('PlaybackService', () => {

it('should add tracks to the queue unshuffled if shuffle is disabled', () => {
// Arrange
queueMock.setup((x) => x.setTracks(trackModels, false)).returns(() => trackModels);
const service: PlaybackServiceBase = createService();

// Act
Expand All @@ -842,6 +843,7 @@ describe('PlaybackService', () => {

it('should add tracks to the queue shuffled if shuffle is enabled', () => {
// Arrange
queueMock.setup((x) => x.setTracks(trackModels, true)).returns(() => trackModels);
const service: PlaybackServiceBase = createService();
service.toggleIsShuffled();

Expand All @@ -854,6 +856,7 @@ describe('PlaybackService', () => {

it('should start playback', () => {
// Arrange
queueMock.setup((x) => x.setTracks(trackModels, false)).returns(() => trackModels);
const service: PlaybackServiceBase = createService();

audioPlayerMock.reset();
Expand All @@ -874,6 +877,7 @@ describe('PlaybackService', () => {

it('should raise an event that playback has started, containing the current track and if a next track is being played.', () => {
// Arrange
queueMock.setup((x) => x.setTracks(trackModels, false)).returns(() => trackModels);
const service: PlaybackServiceBase = createService();

let receivedTrack: TrackModel | undefined;
Expand Down
5 changes: 3 additions & 2 deletions src/app/services/playback/playback.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ export class PlaybackService implements PlaybackServiceBase {
return;
}

this.queue.setTracks(tracksToEnqueue, this.isShuffled);
this.play(trackToPlay, false);
const enqueuedTracks: TrackModel[] = this.queue.setTracks(tracksToEnqueue, this.isShuffled);
const enqueuedTrackToPlay: TrackModel = enqueuedTracks.filter((x) => x.path === trackToPlay.path)[0];
this.play(enqueuedTrackToPlay, false);
}

public enqueueAndPlayArtist(artistToPlay: ArtistModel, artistType: ArtistType): void {
Expand Down
9 changes: 7 additions & 2 deletions src/app/services/playback/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ export class Queue {
private _tracks: TrackModel[] = [];
private playbackOrder: number[] = [];

public constructor(private shuffler: Shuffler, private logger: Logger) {}
public constructor(
private shuffler: Shuffler,
private logger: Logger,
) {}

public get tracks(): TrackModel[] {
return this._tracks;
Expand All @@ -28,7 +31,7 @@ export class Queue {
return this._tracks.length;
}

public setTracks(tracksToSet: TrackModel[], shuffle: boolean): void {
public setTracks(tracksToSet: TrackModel[], shuffle: boolean): TrackModel[] {
this._tracks = tracksToSet.map((x) => x.clone());

if (shuffle) {
Expand All @@ -38,6 +41,8 @@ export class Queue {
}

this.logger.info(`Set '${tracksToSet?.length}' tracks. Shuffle=${shuffle}`, 'Queue', 'setTracks');

return this._tracks;
}

public addTracks(tracksToAdd: TrackModel[]): void {
Expand Down

0 comments on commit 7cbaec7

Please sign in to comment.