Skip to content

Commit

Permalink
fix(audioButtons): fixed bug stopping play and pause buttons from wor…
Browse files Browse the repository at this point in the history
…king due to model functions being attached to audio element from previous page
  • Loading branch information
peichins committed Nov 23, 2017
1 parent dc052df commit b206c52
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 42 deletions.
15 changes: 2 additions & 13 deletions src/app/audio/bawAudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,13 @@ angular.module("bawApp.audio.bawAudio", [])
controller: [
"$scope",
"$route",
function ($scope, $route) {
"$timeout",
function ($scope, $route, $timeout) {

var self = this;

$scope.audioElementModel = self.audioElementModel;

/**
* Reload audio when the source changes. Without this it won't change the audio
* even though the src attribute changes
*/
$scope.$watch("media", function () {
console.log("new media loaded");
document.querySelector("audio").load();
//$route.reload();
});



}],
bindings: {
audioElementModel: "=",
Expand Down
21 changes: 8 additions & 13 deletions src/app/audio/ngAudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ angular.module("bawApp.directives.ngAudio", [
restrict: "A",
link: function (scope, elements, attributes, controller) {
var element = elements[0];

if (element.nodeName !== "AUDIO") {
throw "Cannot put ngAudio element on an element that is not a <audio />";
}
Expand All @@ -46,32 +47,27 @@ angular.module("bawApp.directives.ngAudio", [
* NOTE: only some properties are bound forward
*/

// scope.$watch(function () {
// return element;
// }, function (newValue, oldValue) {
// console.log(newValue);
// }, true);

var target;
scope.$watch(function () {
return expression(scope);
}, function (newValue, oldValue) {
target = newValue;
// attach modification functions to model
target.play = play;
target.pause = pause;
});

// volume
scope.$watch(function () {
return target ? target.volume : null;
}, function updateVolume(newValue, oldValue) {
console.log("changing the volume");
element.volume = newValue;
});

// muted
scope.$watch(function () {
return target ? target.muted : null;
}, function updateMuted(newValue, oldValue) {
console.log("changing the muted value");
element.muted = newValue === null ? null : !!newValue;
});

Expand Down Expand Up @@ -126,6 +122,10 @@ angular.module("bawApp.directives.ngAudio", [
function updateState(event) {
console.debug("ngAudio:audioElement:eventType: ", event ? event.type : "<unknown>", element.currentTime);

if (scope.$root === null) {
return;
}

scope.$root.$safeApply(scope, function () {
if (attributes.ngAudio) {
var target = expression(scope);
Expand All @@ -134,13 +134,8 @@ angular.module("bawApp.directives.ngAudio", [
target = expression(scope);
}

// attach modification functions to model
target.play = target.play || play;
target.pause = target.pause || pause;

target.currentState = event && event.type || "unknown";


updateObject(element ,target);

target.isPlaying = !element.paused;
Expand Down
3 changes: 0 additions & 3 deletions src/app/citizenScience/bristlebird/bristlebird.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class BristlebirdController {
// to be populated after getting samples from dataset
$scope.media = null;


$scope.onboardingSteps = [
{
element: document.querySelector(".citizen-science .spectrogram-wrapper"),
Expand Down Expand Up @@ -102,7 +101,6 @@ class BristlebirdController {

$scope.currentSample = {};


// the model passed to ngAudio
$scope.audioElementModel = CitizenScienceCommon.getAudioModel();

Expand All @@ -114,7 +112,6 @@ class BristlebirdController {
$scope.labels = labels;
});


SampleLabels.init($scope.csProject, $scope.samples, $scope.labels);

$scope.$on("label-toggle", function (e, labelNumber, value) {
Expand Down
18 changes: 7 additions & 11 deletions src/app/citizenScience/bristlebird/listen.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,19 @@ <h2>Eastern Bristlebird Search
<img id="spectrogram" class="spectrogram" ng-src="{{media.available.image.png.url}}">
<div position-line media="media" audio-data="audioElementModel" image-id="'spectrogram'"></div>
</div>
<!--<audio id="citsci-sample" ng-audio="audioElementModel">-->
<!--<source ng-repeat="key in media.available.audioOrder"-->
<!--ng-src="{{media.available.audio[key].url}}" src=""-->
<!--type="{{media.available.audio[key].mimeType}}">-->
<!--Your browser does not support the audio element.-->
<!--</audio>-->

<baw-audio audio-element-model="audioElementModel" media="media"></baw-audio>


<audio id="citsci-sample" ng-audio="audioElementModel">
<source ng-repeat="key in media.available.audioOrder"
ng-src="{{media.available.audio[key].url}}" src=""
type="{{media.available.audio[key].mimeType}}">
Your browser does not support the audio element.
</audio>

<!--<baw-audio audio-element-model="audioElementModel" media="media"></baw-audio>-->

</div>
</div>



<nav class="cs-progress">

<dataset-progress audio-element-model="audioElementModel" current-sample="currentSample" num-viewed="numSamplesViewed"></dataset-progress>
Expand Down
10 changes: 8 additions & 2 deletions src/app/citizenScience/datasetProgress/datasetProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ angular.module("bawApp.components.progress", ["bawApp.citizenScience.csApiMock"]

$scope.selectItem($routeParams.sampleNum);

$scope.$watch($routeParams, function (newVal, oldVal) {
/**
* Load the new sample whenever the route params change.
*/
$scope.$watch(
function () {
return $routeParams.sampleNum;
}, function (newVal, oldVal) {
console.log("route params changed from ", oldVal, "to", newVal);

// call the api to get the sample based on the route params
$scope.selectItem($routeParams.sampleNum);

}, true);
});

//TODO: this gets called constantly while the audio is playing
/**
Expand Down

0 comments on commit b206c52

Please sign in to comment.