Hi everyone,

The solution to this might be very simple, but I still can't figure it out. 
So here it goes:

I am creating a Podcast app using Ionic and AngularJS

I have two views:

   - 
   
   List View (displaying all podcasts)
   - 
   
   Detailed View (selected podcast)
   
<https://lh3.googleusercontent.com/-eTSABkn3P1E/WSSRAE8h8OI/AAAAAAAAQ6E/CWs3gTiMZ7cIdvq3yAgymwV9Dq8uiLHJgCLcB/s1600/1.jpg>
Every time the user opens detailed view I grab the new podcast URL from the 
database and I load it in a new Audio object.

va sound = new Audio($scope.mp3);


If I play a podcast and then go back on the list view and select another 
podcast and play it, the currently playing one doesen't stop and then I 
have two (or many) playing at the same time.


<https://lh3.googleusercontent.com/-lzBZl0r_Uz8/WSSRRuL7LUI/AAAAAAAAQ6I/lmWZf0BsAFcc2900zkZR-jGfW7o02IOowCLcB/s1600/2.jpg>

// Podcast Detailed Controller
.controller('PodcastCtrlDetailed', function($scope, $http, $stateParams, 
$firebaseArray) {

  // URL Parameter
  var podcastRefID = $stateParams.playlistId;

  const oneRef = 
firebase.database().ref().child('podcasts').child(podcastRefID).on("value", 
function(snapshot) {

    $scope.mp3 = snapshot.val().audio;
    var sound = new Audio($scope.mp3);

    $scope.playSong = function() {
      
      if (sound.duration > 0 && !sound.paused) {
        sound.pause();
      } else {
          sound.play();
      }

    }; 


  }, function (errorObject) {
    console.log("The read failed: " + errorObject.code);
  });


});


And this is how I initalise the Play and Pause


<i class="ion-play" ng-click="playSong()" ></i> 


Is there any way of making the currently playing podcast stop and start the 
newly selected one?

Thanks in advance! I've been struggeling with this for a while now :/

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to