Skip to content
Closed
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2015-2017 Ariel Faur. [https://github.com/arielfaur](https://github.com/arielfaur), [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
135 changes: 135 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Ionic Audio for Ionic 2

An audio player plugin for Ionic that works out of the box in the browser and device using an underlying audio provider depending on the environment. When running inside the browser the plugin will default to a Web Audio provider, whereas on a device it will switch to Cordova Media if cordova-plugin-media is available, otherwise falls back to web audio.

## API Docs

[API](http://arielfaur.github.io/ionic-audio/2.0/docs/modules/ionic-audio.html)

## Demo

[Demo](http://arielfaur.github.io/ionic-audio-example/)

## Installation

Make sure you have Ionic and Angular installed.

```
npm install --save ionic-audio
```

**For Ionic 2 version 2.0.0 to 2.1.0:**
```
npm install --save [email protected]
```


```typescript
import { IonicAudioModule } from 'ionic-audio';

@NgModule({
imports: [
IonicAudioModule.forRoot()
]
})
export class AppModule {}
```

## Usage

**Import and inject `AudioProvider` where needed (optional):**

```typescript
import {Component, Provider} from '@angular/core';
import { AudioProvider } from 'ionic-audio';

@Component({
templateUrl: 'build/pages/page1/page1.html'
})
export class Page1 {
myTracks: any[];
allTracks: any[];

constructor(private _audioProvider: AudioProvider) {
// plugin won't preload data by default, unless preload property is defined within json object - defaults to 'none'
this.myTracks = [{
src: 'https://archive.org/download/JM2013-10-05.flac16/V0/jm2013-10-05-t12-MP3-V0.mp3',
artist: 'John Mayer',
title: 'Why Georgia',
art: 'img/johnmayer.jpg',
preload: 'metadata' // tell the plugin to preload metadata such as duration for this track, set to 'none' to turn off
},
{
src: 'https://archive.org/download/JM2013-10-05.flac16/V0/jm2013-10-05-t30-MP3-V0.mp3',
artist: 'John Mayer',
title: 'Who Says',
art: 'img/johnmayer.jpg',
preload: 'metadata' // tell the plugin to preload metadata such as duration for this track, set to 'none' to turn off
}];
}

ngAfterContentInit() {
// get all tracks managed by AudioProvider so we can control playback via the API
this.allTracks = this._audioProvider.tracks;
}

playSelectedTrack() {
// use AudioProvider to control selected track
this._audioProvider.play(this.selectedTrack);
}

pauseSelectedTrack() {
// use AudioProvider to control selected track
this._audioProvider.pause(this.selectedTrack);
}

onTrackFinished(track: any) {
console.log('Track finished', track)
}
}
```

**Add components to views:**

```html
<ion-list>
<audio-track #audio *ngFor="let track of myTracks" [track]="track" (onFinish)="onTrackFinished($event)">
<ion-item>
<ion-thumbnail item-left>
<img src="{{audio.art}}">
<audio-track-play dark [audioTrack]="audio"><ion-spinner></ion-spinner></audio-track-play>
</ion-thumbnail>
<div item-content style="width:100%">
<p><strong>{{audio.title}}</strong> ⚬ <em>{{audio.artist}}</em></p>
<audio-track-progress-bar dark duration progress [audioTrack]="audio" [ngStyle]="{visibility: audio.completed > 0 ? 'visible' : 'hidden'}"></audio-track-progress-bar>
</div>
</ion-item>
</audio-track>
</ion-list>
```

# Ionic 1.x

The source code for [Ionic 1.x](https://github.com/arielfaur/ionic-audio)
See [http://arielfaur.github.io/ionic-audio/index.html](http://arielfaur.github.io/ionic-audio/index.html) for Demo and Installation

# Contributing

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

Thank you, [contributors]!

[contributors]: https://github.com/arielfaur/ionic-audio/graphs/contributors


# Author

* **Ariel Faur** [@arielfaur](https://github.com/arielfaur)

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
28 changes: 14 additions & 14 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "2.2.1",
"@angular/compiler": "2.2.1",
"@angular/compiler-cli": "2.2.1",
"@angular/core": "2.2.1",
"@angular/forms": "2.2.1",
"@angular/http": "2.2.1",
"@angular/platform-browser": "2.2.1",
"@angular/platform-browser-dynamic": "2.2.1",
"@angular/platform-server": "2.2.1",
"@ionic/storage": "1.1.7",
"ionic-angular": "2.1.0",
"@angular/common": "2.4.8",
"@angular/compiler": "2.4.8",
"@angular/compiler-cli": "2.4.8",
"@angular/core": "2.4.8",
"@angular/forms": "2.4.8",
"@angular/http": "2.4.8",
"@angular/platform-browser": "2.4.8",
"@angular/platform-browser-dynamic": "2.4.8",
"@angular/platform-server": "2.4.8",
"@ionic/storage": "2.0.0",
"ionic-angular": "2.2.0",
"ionic-native": "2.4.1",
"ionicons": "3.0.0",
"rxjs": "5.0.0-beta.12",
"rxjs": "5.0.1",
"sw-toolbox": "3.4.0",
"zone.js": "0.6.26",
"ionic-audio": "^2.3.2"
"zone.js": "0.7.2",
"ionic-audio": "^2.3.4"
},
"devDependencies": {
"@ionic/app-scripts": "1.1.4",
Expand Down
3 changes: 2 additions & 1 deletion dist/ionic-audio-web-track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ export class WebAudioTrack implements IAudioTrack {
private _id: number;
private _isLoading: boolean;
private _hasLoaded: boolean;
constructor(public src: string, @Optional() public preload: string = 'none', @Optional() private ctx: AudioContext = undefined) {
constructor(public src: string, @Optional() public preload: string = 'none') {
// audio context not needed for now
// @Optional() private ctx: AudioContext = undefined
// this.ctx = this.ctx || new AudioContext();

this.createAudio();
Expand Down
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@
"typings": "./dist/index.d.ts",
"scripts": {
"prepublish": "tsc -p ./",
"build": "npm install && npm run prepublish",
"release": "npm run build && npm publish",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@angular/common": "2.2.1",
"@angular/compiler": "2.2.1",
"@angular/compiler-cli": "2.2.1",
"@angular/core": "2.2.1",
"@angular/forms": "2.2.1",
"@angular/http": "2.2.1",
"@angular/platform-browser": "2.2.1",
"@angular/platform-browser-dynamic": "2.2.1",
"@angular/platform-server": "2.2.1",
"ionic-angular": "2.1.0",
"rxjs": "5.0.0-beta.12",
"zone.js": "0.6.26"
},
"dependencies": {},
"devDependencies": {
"@angular/core": "2.4.8",
"@angular/common": "2.4.8",
"@angular/compiler": "2.4.8",
"@angular/compiler-cli": "2.4.8",
"@angular/forms": "2.4.8",
"@angular/http": "2.4.8",
"@angular/platform-browser": "2.4.8",
"@angular/platform-browser-dynamic": "2.4.8",
"@angular/platform-server": "2.4.8",
"ionic-angular": "2.2.0",
"rxjs": "5.0.1",
"zone.js": "0.7.2",
"typescript": "2.0.9"
},
"repository": {
Expand Down