4 |
5 |
6 |
7 |
8 | A library for loading and playing audio using HTML 5 for Angular 7/8/9/10/11/12.
9 |
10 | Installation
11 | ngx-audio-player
is available via npm and yarn
15 | Using npm:
16 | $ npm install ngx-audio-player --save
17 | Using yarn:
18 | $ yarn add ngx-audio-player
19 | Getting Started
20 | NgxAudioPlayerModule needs Angular Material.
Make sure you have installed below
21 | dependencies with same or higher version than mentioned.
22 | "@angular/core": "^12.0.0"
23 | "@angular/common": "^12.0.0"
24 | "@angular/material": "^12.0.0"
25 | "rxjs": "^6.6.0"
26 | Import NgxAudioPlayerModule
in the root module(AppModule
):
27 |
28 |
29 | import {{'{'}} NgxAudioPlayerModule {{'}'}} from 'ngx-audio-player';
32 |
33 | @NgModule({{'{'}}
34 | imports: [
35 |
36 | NgxAudioPlayerModule
37 | ]
38 | {{'}'}})
39 | export class AppModule {{'{'}} {{'}'}}
40 | Usage
41 |
42 |
43 | Simple Audio Player
44 |
45 | HTML
46 | <ngx-audio-player [autoPlay]="false" muted="muted"
47 |
48 | [playlist]="mssapPlaylist"
49 | [disablePositionSlider]="mssapDisablePositionSlider"
50 | [displayRepeatControls]="mssapDisplayRepeatControls"
51 | [displayVolumeControls]="mssapDisplayVolumeControls"
52 | [displayVolumeSlider]="mssapDisplayVolumeSlider"
53 |
54 | [displayTitle]="mssapDisplayTitle"
55 |
56 | (trackEnded)="onEnded($event)">
57 |
58 | </ngx-audio-player>
59 |
60 |
61 | TS
62 |
63 | import {{'{'}} Track {{'}'}} from 'ngx-audio-player';
65 | .
66 | .
67 | mssapDisplayTitle = true;
68 | mssapDisablePositionSlider = true;
69 | mssapDisplayRepeatControls = true;
70 | mssapDisplayVolumeControls = true;
71 | mssapDisplayVolumeSlider = false;
72 |
73 |
74 | mssapPlaylist: Track[] = [
75 | {{'{'}}
76 | title: 'Audio Title',
77 | link: 'Link to Audio URL',
78 | artist: 'Artist',
79 | duration: 'Duration'
80 | {{'}'}}
81 | ];
82 |
83 |
84 |
85 | mssapPlaylist: Track[] = [
86 | {{'{'}}
87 | title: 'Audio Title',
88 | link: 'Link to Streaming URL',
89 | mediaType: 'stream'
90 | {{'}'}}
91 | ];
92 |
93 |
94 | onEnded(event) {{'{'}}
95 | console.log(event);
96 |
97 |
98 |
99 | {{'}'}}
100 |
101 |
102 |
103 | Advanced Audio Player
104 |
105 | HTML
106 |
107 |
108 | <ngx-audio-player [autoPlay]="false" muted="muted"
109 |
110 | [playlist]="msaapPlaylist"
111 | [disablePositionSlider]="msaapDisablePositionSlider"
112 | [displayRepeatControls]="msaapDisplayRepeatControls"
113 | [displayVolumeControls]="msaapDisplayVolumeControls"
114 | [displayVolumeSlider]="msaapDisplayVolumeSlider"
115 |
116 | [displayTitle]="msaapDisplayTitle"
117 |
118 | [displayPlaylist]="msaapDisplayPlayList"
119 | [pageSizeOptions]="msaapPageSizeOptions"
120 |
121 | [tableHeader]="msaapTableHeader"
122 | [titleHeader]="msaapTitleHeader"
123 | [artistHeader]="msaapArtistHeader"
124 | [durationHeader]="msaapDurationHeader"
125 |
126 | [displayArtist]="msaapDisplayArtist"
127 | [displayDuration]="msaapDisplayDuration"
128 | [expanded]="true"
129 |
130 | (trackPlaying)="onTrackPlaying($event)"
131 | (trackPaused)="onTrackPaused($event)"
132 | (trackEnded)="onEnded($event)"
133 | (nextTrackRequested)="onNextTrackRequested($event)"
134 | (previousTrackRequested)="onPreviousTrackRequested($event)"
135 | (trackSelected)="onTrackSelected($event)">
136 |
137 | </ngx-audio-player>
138 |
139 |
140 | TS
141 |
142 | import {{'{'}} Track {{'}'}} from 'ngx-audio-player';
144 |
145 | .
146 | .
147 |
148 |
149 | msaapDisplayPlayList = true;
150 | msaapDisablePositionSlider = true;
151 | msaapDisplayRepeatControls = true;
152 | msaapDisplayVolumeControls = true;
153 | msaapDisplayVolumeSlider = false;
154 |
155 |
156 | msaapDisplayTitle = true;
157 |
158 |
159 | msaapPageSizeOptions = [2,4,6];
160 | msaapDisplayArtist = false;
161 | msaapDisplayDuration = false;
162 |
163 |
164 | msaapTableHeader = 'My Playlist';
165 | msaapTitleHeader = 'My Title';
166 | msaapArtistHeader = 'My Artist';
167 | msaapDurationHeader = 'My Duration';
168 |
169 |
170 |
171 | msaapPlaylist: Track[] = [
172 | {{'{'}}
173 | title: 'Audio One Title',
174 | link: 'Link to Audio One URL',
175 | artist: 'Artist',
176 | duration: 'Duration'
177 | {{'}'}},
178 | {{'{'}}
179 | title: 'Audio Two Title',
180 | link: 'Link to Audio Two URL',
181 | artist: 'Artist',
182 | duration: 'Duration'
183 | {{'}'}},
184 | {{'{'}}
185 | title: 'Audio Three Title',
186 | link: 'Link to Audio Three URL',
187 | artist: 'Artist',
188 | duration: 'Duration'
189 | {{'}'}},
190 | ];
191 |
192 |
193 |
194 | onTrackPlaying(event) {{'{'}}
195 | console.log(event);
196 |
197 |
198 |
199 | {{'}'}}
200 |
201 |
202 | onTrackPaused(event) {{'{'}}
203 | console.log(event);
204 |
205 |
206 |
207 | {{'}'}}
208 |
209 | onEnded(event) {{'{'}}
210 | console.log(event);
211 |
212 |
213 |
214 | {{'}'}}
215 |
216 | onNextTrackRequested(event) {{'{'}}
217 | console.log(event);
218 |
219 |
220 |
221 | {{'}'}}
222 |
223 |
224 | onPreviousTrackRequested(event) {{'{'}}
225 | console.log(event);
226 |
227 |
228 |
229 | {{'}'}}
230 |
231 | onTrackSelected(event) {{'{'}}
232 | console.log(event);
233 |
234 |
235 |
236 | {{'}'}}
237 |
238 |
239 | Properties
240 |
241 |
242 |
243 | Name |
244 | Description |
245 | Type |
246 |
247 |
248 |
249 |
250 | @Input() playlist: Track[]; |
251 | playlist containing array of title and link |
252 | mandatory |
253 |
254 |
255 | @Input()
256 | autoPlay = false;
257 | |
258 | true - if the audio needs to be played automatically |
259 | optional |
260 |
261 |
262 |
263 | Player Controls
264 | |
265 |
266 |
267 | @Input()
268 | startOffset = 0;
269 | |
270 | offset from start of audio file in seconds |
271 | optional |
272 |
273 |
274 | @Input()
275 | endOffset = 0;
276 | |
277 | offset from end of audio file in seconds |
278 | optional |
279 |
280 |
281 | @Input() disablePositionSlider = false; |
282 | true - if the position slider needs to be disabled |
283 | optional |
284 |
285 |
286 | @Input() displayRepeatControls = true; |
287 | false - if the repeat controls needs to be hidden |
288 | optional |
289 |
290 |
291 | @Input() repeat: "all" | "one" | "none" = 'all'; |
292 | repeat all or one or none |
293 | optional |
294 |
295 |
296 | @Input() displayVolumeControls = true; |
297 | false - if the volume controls needs to be hidden |
298 | optional |
299 |
300 |
301 | @Input() displayVolumeSlider = false; |
302 | true - if the volume slider should be shown |
303 | optional |
304 |
305 |
306 |
307 | Title Marquee Control
308 | |
309 |
310 |
311 | @Input() displayTitle: true; |
312 | false - if the audio title needs to be hidden |
313 | optional |
314 |
315 |
316 |
317 | Playlist Controls
318 | |
319 |
320 |
321 | @Input() displayPlaylist: true; |
322 | false - if the playlist needs to be hidden |
323 | optional |
324 |
325 |
326 | @Input() pageSizeOptions = [10, 20, 30]; |
327 | number of items to be displayed in the playlist |
328 | optional |
329 |
330 |
331 | @Input() expanded = true; |
332 | false - if the playlist needs to be minimized |
333 | optional |
334 |
335 |
336 | @Input() displayArtist = false; |
337 | true - if the artist data is to be shown |
338 | optional |
339 |
340 |
341 | @Input() displayDuration = false; |
342 | true - if the track duration is to be shown |
343 | optional |
344 |
345 |
346 |
347 | Localisation Controls
348 | |
349 |
350 |
351 | @Input() tableHeader = 'Playlist'; |
352 | true - if the track duration is to be shown |
353 | optional |
354 |
355 |
356 | @Input() titleHeader = 'Title'; |
357 | true - if the track duration is to be shown |
358 | optional |
359 |
360 |
361 | @Input() artistHeader = 'Artist'; |
362 | true - if the track duration is to be shown |
363 | optional |
364 |
365 |
366 | @Input() durationHeader = 'Duration'; |
367 | true - if the track duration is to be shown |
368 | optional |
369 |
370 |
371 |
372 | Callback Events
373 | |
374 |
375 |
376 | @Output() trackPlaying: EventEmitter<EventResponse> |
377 | triggers when the track starts playing |
378 | optional |
379 |
380 |
381 | @Output() trackPaused: EventEmitter<EventResponse> |
382 | triggers when the track is paused |
383 | optional |
384 |
385 |
386 | @Output() trackEnded: EventEmitter<EventResponse> |
387 | triggers when the track ends |
388 | optional |
389 |
390 |
391 | @Output() nextTrackRequested: EventEmitter<EventResponse> |
392 | triggers when the next track is requested |
393 | optional |
394 |
395 |
396 | @Output() previousTrackRequested: EventEmitter<EventResponse> |
397 | triggers when the previous track is requested |
398 | optional |
399 |
400 |
401 | @Output() trackSelected: EventEmitter<EventResponse> |
402 | triggers when any track is selected from playlist |
403 | optional |
404 |
405 |
406 |
407 |
408 | Versioning
409 | ngx-audio-player will be maintained under the Semantic Versioning guidelines.
410 | Releases will be numbered with the following format:
411 |
412 | <major>.<minor>.<patch>
413 |
414 | For more information on SemVer, please visit http://semver.org.
416 |
417 |
418 | Contributors ✨
419 | Thanks goes to these wonderful people:
420 |
511 | License
512 | The MIT License (MIT)
513 |