Skip to content

Commit

Permalink
fixed pause button bug
Browse files Browse the repository at this point in the history
v.1.2.4
  • Loading branch information
Ariel Faur committed Jul 4, 2015
1 parent 7b79a91 commit fb90e1b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.2.4

- fixed bug where pause button was disabled and was not possible to stop playback

## v1.2.3

- fixed slider bug to allow seeking-to when track is paused
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ionic-audio",
"description": "Ionic UI for the Cordova Media Plugin",
"version": "1.2.3",
"version": "1.2.4",
"homepage": "https://github.com/arielfaur/ionic-audio.git",
"license": "MIT",
"private": false,
Expand All @@ -11,6 +11,6 @@
"angular-mocks": "~1.3.x"
},
"devDependencies": {
"ionic": "driftyco/ionic-bower#1.0.0-rc.5"
"ionic": "driftyco/ionic-bower#1.0.1"
}
}
24 changes: 13 additions & 11 deletions dist/ion-audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ angular.module('ionic-audio', ['ionic'])
restrict: 'EA',
scope: {},
require: ['ionAudioControls', '^^ionAudioTrack'],
controller: ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
controller: ['$scope', '$element', function($scope, $element) {
var spinnerElem = $element.find('ion-spinner'), hasLoaded, self = this;

spinnerElem.addClass('ng-hide');
Expand Down Expand Up @@ -334,19 +334,21 @@ angular.module('ionic-audio', ['ionic'])
}])
.directive('ionAudioPlay', [function() {
return {
scope: true,
//scope: true,
restrict: 'A',
require: '^^ionAudioControls',
link: function(scope, element, attrs, controller) {
var isLoading, currentStatus = 0;

var init = function() {
isLoading = false;
element.addClass('ion-play');
element.removeClass('ion-pause');
element.text(attrs.textPlay);
};

var setText = function() {
if (!attrs.textPlay || !attrs.textPause) return '';
if (!attrs.textPlay || !attrs.textPause) return;

element.text((element.text() == attrs.textPlay ? attrs.textPause : attrs.textPlay));
};
Expand All @@ -357,22 +359,22 @@ angular.module('ionic-audio', ['ionic'])
};

element.on('click', function() {
element.prop('disabled', true);
// call main directive's play method
if (isLoading) return; // debounce multiple clicks

controller.playTrack();
togglePlaying();
if (currentStatus == 0) isLoading = true;
});

var unbindStatusListener = scope.$watch('track.status', function (status) {
// Media.MEDIA_NONE or Media.MEDIA_STOPPED
if (status == 0 || status == 4) {
init();
} else if (status == 2) { // Media.MEDIA_RUNNING
isLoading = false;
}

// Media.MEDIA_RUNNING or Media.MEDIA_PAUSED
if (status == 2 || status == 3) {
element.prop('disabled', false);
}
currentStatus = status;
});

init();
Expand Down Expand Up @@ -417,8 +419,9 @@ angular.module('ionic-audio', ['ionic'])
return { visibility: angular.isDefined(attrs.displayInfo) && (scope.track.title || scope.track.artist) ? 'visible' : 'hidden'}
};

// disable slider if track hasn't loaded
// disable slider if track is not playing
var unbindStatusListener = scope.$watch('track.status', function(status) {
// disable if track hasn't loaded
slider.prop('disabled', status == 0); // Media.MEDIA_NONE
});

Expand All @@ -443,7 +446,6 @@ angular.module('ionic-audio', ['ionic'])
if (angular.isDefined(unbindTrackListener)) {
unbindTrackListener();
}
MediaManager.destroy();
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion example-audio/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "example-audio",
"private": "true",
"devDependencies": {
"ionic": "driftyco/ionic-bower#1.0.0-rc.5"
"ionic": "driftyco/ionic-bower#1.0.1"
},
"dependencies": {
"ngCordova": "*"
Expand Down
24 changes: 13 additions & 11 deletions example-audio/www/js/ion-audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ angular.module('ionic-audio', ['ionic'])
restrict: 'EA',
scope: {},
require: ['ionAudioControls', '^^ionAudioTrack'],
controller: ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
controller: ['$scope', '$element', function($scope, $element) {
var spinnerElem = $element.find('ion-spinner'), hasLoaded, self = this;

spinnerElem.addClass('ng-hide');
Expand Down Expand Up @@ -334,19 +334,21 @@ angular.module('ionic-audio', ['ionic'])
}])
.directive('ionAudioPlay', [function() {
return {
scope: true,
//scope: true,
restrict: 'A',
require: '^^ionAudioControls',
link: function(scope, element, attrs, controller) {
var isLoading, currentStatus = 0;

var init = function() {
isLoading = false;
element.addClass('ion-play');
element.removeClass('ion-pause');
element.text(attrs.textPlay);
};

var setText = function() {
if (!attrs.textPlay || !attrs.textPause) return '';
if (!attrs.textPlay || !attrs.textPause) return;

element.text((element.text() == attrs.textPlay ? attrs.textPause : attrs.textPlay));
};
Expand All @@ -357,22 +359,22 @@ angular.module('ionic-audio', ['ionic'])
};

element.on('click', function() {
element.prop('disabled', true);
// call main directive's play method
if (isLoading) return; // debounce multiple clicks

controller.playTrack();
togglePlaying();
if (currentStatus == 0) isLoading = true;
});

var unbindStatusListener = scope.$watch('track.status', function (status) {
// Media.MEDIA_NONE or Media.MEDIA_STOPPED
if (status == 0 || status == 4) {
init();
} else if (status == 2) { // Media.MEDIA_RUNNING
isLoading = false;
}

// Media.MEDIA_RUNNING or Media.MEDIA_PAUSED
if (status == 2 || status == 3) {
element.prop('disabled', false);
}
currentStatus = status;
});

init();
Expand Down Expand Up @@ -417,8 +419,9 @@ angular.module('ionic-audio', ['ionic'])
return { visibility: angular.isDefined(attrs.displayInfo) && (scope.track.title || scope.track.artist) ? 'visible' : 'hidden'}
};

// disable slider if track hasn't loaded
// disable slider if track is not playing
var unbindStatusListener = scope.$watch('track.status', function(status) {
// disable if track hasn't loaded
slider.prop('disabled', status == 0); // Media.MEDIA_NONE
});

Expand All @@ -443,7 +446,6 @@ angular.module('ionic-audio', ['ionic'])
if (angular.isDefined(unbindTrackListener)) {
unbindTrackListener();
}
MediaManager.destroy();
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ionic-audio",
"private": false,
"version": "1.2.3",
"version": "1.2.4",
"description": "Ionic UI for the Cordova Media Plugin",
"repository": "https://github.com/arielfaur/ionic-audio.git",
"license": "MIT",
Expand Down

0 comments on commit fb90e1b

Please sign in to comment.