Let's build a mobile application with Ionic Framework #5

After listings the audio books , now we need to playing some sound . since we are dealing with html5 hybride application , no way better way  than using HTML5 Audio api !



The idea is just creating two functions inside our controller : play() , and pause()

But we declare a global variable called audio

var audio = new Audio();

NB : the URL  for streaming these audio books is http://www.litteratureaudio.net  + Book. preview(data.json)




// play function
$scope.play = function(preview){
   
  var url =  "http://www.litteratureaudio.net"  + preview
  audio = new Audio(url)
  audio.play()

}
// pause function
$scope.pause = function(){
audio.pause()
}


Now we have our two functions, they still have to detect when the user click on play with angularjs ng-click , we will also

pass the parameter preview to listen to the good book


ng-click="play({{book.Book.preview}})"



Comments

Popular posts from this blog

Twitter API with PHP

Realtime Chat Application with CakePHP and Socket.IO #1

Let's build a mobile application with Ionic Framework #3