diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..d9e33b3 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2015-2017 Ariel Faur. [https://github.com/arielfaur](https://github.com/arielfaur), ariel.faur@gmail.com + +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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4ff6a5e --- /dev/null +++ b/README.md @@ -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 ionic-audio@2.3.4 +``` + + +```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 + + + + + + + +
+

{{audio.title}}{{audio.artist}}

+ +
+
+
+
+``` + +# 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 \ No newline at end of file diff --git a/demo/package.json b/demo/package.json index 724b6fb..514e0ee 100644 --- a/demo/package.json +++ b/demo/package.json @@ -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", diff --git a/dist/ionic-audio-web-track.ts b/dist/ionic-audio-web-track.ts index 4e90feb..65bf560 100644 --- a/dist/ionic-audio-web-track.ts +++ b/dist/ionic-audio-web-track.ts @@ -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(); diff --git a/package.json b/package.json index a73a4e4..15ff96a 100644 --- a/package.json +++ b/package.json @@ -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": {