Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to build an angularJS audio player?

I want to create an angularJS audio player based on soundmanager2. Before starting coding, I'm looking for advices on my current thought.

I plan to separate both player logic (sound manager wrapper) and player controls (buttons / scrubber)

  • I will also bootstrap the soundmanager with angular using .run()

  • The sound manager will be wrapped into a factory (soundplayer) and will return a soundmanager2 instance

  • The sound controls (buttons and scrubber + ideally a waveform if webaudio is supported) will be handled trough a directive (soundControls) wich will receive a soundplayer instance

What do you thinks ? Am I over engeeneering it, re-inventing the wheel or Am I on a good way ? Advices are welcome.

Thanks!

like image 397
lionelB Avatar asked Nov 02 '22 09:11

lionelB


1 Answers

I finally opted for an event based communication. Once the directive is created, I emit an object containing the API I want to expose.

$scope.controls={
  play: function(){
    snd.play();
  },
  stop: function(){
    snd.stop();
  },
  pause: function(){
    snd.pause();
  },
  rewind: function(){
    snd.stop();
    snd.play();
  }
}
$scope.$emit('snd:init', $scope.controls); 

And from in my controller I handle this

var unregisterInit = $scope.$on('snd:init', function(event, controls){
  unregisterInit();
  playerApi = controls;
});
like image 87
lionelB Avatar answered Nov 08 '22 03:11

lionelB