O'Reilly logo

NativeScript for Angular Mobile Development by Nathanael J. Anderson, Nathan Walker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Scaffolding out the service APIs

Now, let's create the API our services will provide to our app. Starting with PlayerService, we could imagine the following API might be useful to manage tracks and control playback. Most of it should be fairly self-explanatory. We may refactor this later but this is a great start:

  • playing: boolean;
  • tracks: Array<ITrack>;
  • play(index: number): void;
  • pause(index: number): void;
  • addTrack(track: ITrack): void;
  • removeTrack(track: ITrack): void;
  • reorderTrack(track: ITrack, newIndex: number): void;

Create app/modules/player/services/player.service.ts and stub out a few of the methods; some of them we could go ahead and implement:

// angularimport { Injectable } from '@angular/core';// appimport { ITrack } from ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required