Giter Club home page Giter Club logo

audio5js's Introduction

Audio5js - The HTML5 Audio Compatibility Layer

Audio5js a library-agnostic, cross-browser Javascript API for HTML5 Audio, with a Flash fallback for either older browsers or modern browsers without MP3 playback support.

There are many great audio playback libraries out there, each trying to solve a different problem. Audio5js tries to address or avoid the following:

  • Library-agnostic - Audio5js doesn't rely on any external library like jQuery or Dojo, leaving the DOM manipulation part to you.
  • Multi-codec - Audio5js assumes you'll want to support any commonly available audio codec, not just MP3.
  • Lightweight - Audio5js doesn't try and implement anything beyond the bare-bones HTML5 Audio playback API, keeping it light and nimble.
  • Javascript-only - Audio5js doesn't depend on existing <audio> tags in your DOM, but instead lets you programmatically control every aspect of the audio playback cycle from Javascript.
  • No UI - Each player is different, and therefore the visual and functional implementation is left to you. Audio5js aims to facilitate the authoring of your audio player UI by exposing a unified API, and nothing more.
  • No fluffy penguin abuse - Audio5js will never abuse or hurt fluffy penguins wherever they might be.

Getting Started

Audio5js requires two components to work - the Javascript library audio5.js (or the minified version audio5.min.js) and the SWF fallback, found in swf/audio5js.swf.

Simply download the source code, extract, and place both files somewhere in your project. For the purpose of demonstration, let's assume your project directory structure looks like this:

/
-/public
--/js
--- audio5.js
--/swf
--- audio5js.swf

Now, you can include the Javascript in your HTML, and instantiate the Audio player:

<script src="/js/audio5.js"></script>
<script>
  function initAudio () {
    var audio5js = new Audio5js({
      ready: function () {
        this.load('/someaudio.mp3');
        this.play();
      }
    });
  }
  initAudio();
</script>

Configuration

The Audio5js object accepts a configuration object with the following settings:

  • swf_path - The relative path to the MP3 Flash fallback SWF. Defaults to /swf/audio5js.swf.
  • codecs - Array of audio codecs to the player should try and play. Used to initialize the internal audio player based on codec support. Defaults to ['mp3'].
  • throw_errors - A boolean flag indicating whether the player throws errors, or triggers an error event. Defaults to true.
  • format_time - A boolean flag indicating whether playback position and duration should be formatted to a time-string (hh:mm:ss), or remain as unformatted numbers (measured in seconds). Defaults to true.
  • ready - An optional callback that will be called when the player is ready to load and play audio. Called with an object containing player engine (html/flash) and supported codec as argument.

Here's an example configuration using all the settings options above:

<script>

  var initAudio = function () {
    var audio5js = new Audio5js({
      swf_path: '/statics/swf/audio5js.swf',
      throw_errors: true,
      format_time: true,
      ready: function (player) {
        //this points to the audio5js instance
        this.load('/audio/song.mp3');
        this.play();
        //will output {engine:'html', codec: 'mp3'} in browsers that support MP3 playback.
        // will output {engine:'flash', codec: 'mp3'} otherwise
        console.log(player);
      }
    });

  }

  initAudio();
</script>

API

Audio5js exposes the following API:

Instance Methods

  • load - load an audio file from URL
  • play - play loaded audio
  • pause - pause loaded audio
  • playPause - toggle play/pause playback state
  • volume - get / set volume (volume range is 0-1)
  • seek - move playhead position to a given time in seconds
  • destroy - destroys your Audio5js instance. Use to completely remove audio from the DOM and unbind all event listeners.
  • rate - set the playback rate. (playback rate range is 0.5-4.0)

Instance Attributes

  • playing - boolean flag indicating whether audio is playing (true) or paused (false).
  • duration - audio duration in seconds.
  • position - audio playhead position in seconds.
  • load_percent - audio file download percentage (ranges 0 - 100).
  • seekable - audio is seekable (download) or not (streaming).

Class Methods

  • can_play - Utility method to check whether the browser supports a certain audio mime-types.

Audio5js.can_play class method supports the following mime-type queries:

  • mp3 - check for audio/mpeg; codecs="mp3". Example - Audio5js.can_play('mp3')
  • vorbis - check for audio/ogg; codecs="vorbis". Example - Audio5js.can_play('vorbis')
  • opus - check for audio/ogg; codecs="opus". Example - Audio5js.can_play('opus')
  • webm - check for audio/webm; codecs="vorbis". Example - Audio5js.can_play('webm')
  • mp4 - check for audio/mp4; codecs="mp4a.40.5". Example - Audio5js.can_play('mp4')
  • wav - check for audio/wav; codecs="1". Example - Audio5js.can_play('wav')

API Example

<button id="play-pause" type="button">Play / Pause</button>
<button id="move-to-start" type="button">Move to Start</button>
<script>

  var audioReady = function () {
    this.load('/audio/song.mp3');
    var play_pause = document.getElementById('play-pause');
    play_pause.addEventListener('click', playPause.bind(this));
    var move_to_start = document.getElementById('move-to-start');
    move_to_start.addEventListener('click', moveToStart.bind(this));
  }

  var playPause = function () {
    if (this.playing) {
      this.pause();
      this.volume(0);
      console.log(this.position, this.duration, this.load_percent, this.volume());
    } else {
      this.play();
      this.volume(1);
    }
    // or simply call this.playPause();
  }

  var moveToStart = function () {
    this.seek(0);
  }

  var initAudio = function () {
    var audio5js = new Audio5js({
      swf_path: '/statics/swf/audio5js.swf',
      throw_errors: true,
      format_time: true,
      ready: audioReady
    });

  }

  initAudio();
</script>

Events

Like HTML5's Audio, Audio5js exposes events that can be used to capture the state and properties of the audio playback cycle:

  • canplay - triggered when the audio has been loaded can can be played. Analogue to HTML5 Audio canplay event. Note that Firefox will trigger this event after seeking as well - If you're listening to this event, we recommend you use the one('canplay',callback) event listener binding, instead of the on('canplay',callback).
  • play - triggered when the audio begins playing. Analogue to HTML5 Audio play event.
  • pause - triggered when the audio is paused. Analogue to HTML5 Audio pause event.
  • ended - triggered when the audio playback has ended. Analogue to HTML5 Audio ended event.
  • error - triggered when the audio load error occurred. Analogue to HTML5 Audio error event.
  • timeupdate - triggered when the audio playhead position changes (during playback). Analogue to HTML5 Audio timeupdate event.
  • progress - triggered while audio file is being downloaded by the browser. Analogue to HTML5 Audio progress event.
  • seeking - audio is seeking to a new position (in seconds)
  • seeked - audio has been seeked successfully to new position
  • loadedmetadata - MP3 meta-data has been loaded (works with MP3 files only)

Using Events

To subscribe to an event triggered by Audio5js, you can use the on method. Similarly, to unsubscribe from an event, you can use the off method.

The on method accepts the following arguments:

  • event - name of event to subscribe to
  • callback - callback function to execute when the event is triggered
  • context - execution context of callback function (reference to this inside the callback)

The off method accepts the following arguments:

  • event - name of event to unsubscribe from
  • callback - the callback function passed during the event subscription
var audio5js = new Audio5js({
  ready: audioReady
});

var audioReady = function () {
  //this points to the Audio5js instance
  this.on('play', function () { console.log('play'); }, this);
  this.on('pause', function () { console.log('pause'); }, this);
  this.on('ended', function () { console.log('ended'); }, this);

  // timeupdate event passes audio duration and position to callback
  this.on('timeupdate', function (position, duration) {
    console.log(position, duration);
  }, this);

  // progress event passes load_percent to callback
  this.on('progress', function (load_percent) {
    console.log(load_percent);
  }, this);

  //error event passes error object to callback
  this.on('error', function (error) {
    console.log(error.message);
  }, this);
}

Fallbacks and multiple audio sources

Browser-based audio isn't perfect, and it's more than likely that you'll need to serve the same audio in two formats, to support a wider crowd. If you intend to play different audio sources, based on browser codec support, pass a list of desired codecs to the codecs array of the settings object. Note that passed codecs should be listed in order or precedence and that 'mp3' is always the fallback codec in case no other codec is supported by the browser.

Here's an example of initializing Audio5js with multiple audio sources, based on browser support:

  var audio5js = new Audio5js({
    swf_path: '/swf/audio5js.swf',
    codecs: ['mp4', 'vorbis', 'mp3'],
    ready: function(player) {
      var audio_url;
      switch (player.codec) {
        case 'mp4':
          audio_url = '/audio/song.mp4';
          break;
        case 'vorbis':
          audio_url = '/audio/song.ogg';
          break;
        default:
          audio_url = '/audio/song.mp3';
          break;
      }
      this.load(audio_url);
      this.play();
    }
  });

Safari Mobile

Safari mobile won't let you play audio without explicit user interaction. In other words, the initial click on your "play" button needs to load the audio. Here's an example of how to load and play audio on Safari Mobile with Audio5js:

<button id="play-pause" type="button">Play / Pause</button>
<script>
  var loaded = false;

  var playPause = function () {
    if (!loaded) {
      this.one('canplay', function () {
        loaded = true;
        this.play();
      }, this);
      this.load('/song.mp3');
    } else {
      this.playPause();
    }
  }

  var audio5js = new Audio5js({
    swf_path: './flash/audio5js.swf',
    ready: function () {
      var btn = document.getElementById('play-pause');
      btn.addEventListener('click', playPause.bind(this), false);
    }
  });
</script>

AMD / RequireJS

Audio5js comes baked with AMD / RequireJS support. Assuming your public directory structure is as above, here's an example of how to use Audio5js with RequireJS:

Your HTML should look something like this:

<script src="js/require.js" data-main="js/player"></script>

Inside js/player.js you can now require Audio5js like so:

require(["js/audio5"], function (Audio5js) {
  var audio5 = new Audio5js({
    ready: function () {
      this.load('/somesong.mp3');
      this.play();
    }
  });
} );

Ender.js

Audio5js can also be used with Ender.js. Here's how you can add it to your project:

# add audio5 as dependency
$ ender build audio5
//use as a global package
var Audio5js = require('audio5');
var player = new Audio5js({
  swf_path: 'node_modules/audio5/swf/audio5js.swf'
});

// or via the Ender $ object
var play = new $.audio5({
  swf_path: 'node_modules/audio5/swf/audio5js.swf'
});

Angular.js

Audio5js is available as an Angular.js service.

html

<script src="ngAudio5.js"></script>

```javascript```
//inject Audio5 service into our app
var app = angular.module('myapp',['Audio5']);

//Inject the AudioService singleton into our controller
var PlayCtrl = function ($scope, AudioService) {
	//bind AudioService to scope
	$scope.player = AudioService;
	//Load the song, every event, class method and Instance attribute from audio5js are accessible from the template
	$scope.player.load('http://danosongs.com/music/danosongs.com-orb-of-envisage.mp3');

	//example of event binding
	$scope.player.on('progress',function(){
		$scope.$apply();
	})
}

Bower Support

Audio5js is available as a Bower package.

$ bower install audio5js
<script src="components/audio5js/audio5.min.js"></script>
<script>
var player = new Audio5js({
  swf_path: 'components/audio5js/audio5js.swf'
});
</script>

Browser Support

Audio5js doesn't try to please everyone. Having said that, it has been successfully tested on:

  • IE8, IE9
  • Chrome 23 (Mac)
  • Firefox 17 (Mac)
  • Safari 6
  • Opera 12 (Mac)
  • Safari Mobile (iOS 6.0)
  • Webkit Mobile (Android 4.0.4)

TODO

  • Test on mobile browsers (Android).

Contributing

Please feel free to fork, fix and send me pull requests. Alternatively, open tickets for bugs and feature requests.

Credits

Audio5js relies heavily on the wonderful audiojs library. The AS3 code for the fallback MP3 player is taken almost as-is from audiojs, with some minor modifications for more comprehensive event handling.

License

Audio5js is released under the MIT License.

Copyright (c) 2013 Zohar Arad [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Disclaimer

No fluffy penguins were harmed during the making of Audio5js.

audio5js's People

Contributors

aaronpcz avatar altryne avatar byjg avatar davidkaminsky avatar erikagriffin avatar gryzzly avatar mikaelkaron avatar mikerudolph avatar nl0 avatar nogizhopaboroda avatar reubenmoes avatar sethlesky avatar ydaniv avatar yibn2008 avatar zohararad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

audio5js's Issues

onTimeUpdate not triggering on some Android browser

On an Android browser with this UserAgent string Mozilla/5.0 (Linux; U; Android 4.2.2; uk-ua; PAP3350DUO Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 the onTimeUpdate doesn't trigger, and that's because this.audio.buffered.length [audio5.js:579] evaluates to 0 even on a non-streaming (download) file.

Completely remove all Flash components

Hello,

is it possible to use audio5js in a way that no flash components are used at all. Because even if the html player is used, it seems there is an SWF pixel generated. I realized this through Google Page Speed Inisghts.

So the question: Is there a way to have audio5js purely use html and nothing else?

Issue testing angular demo

Hi,

I'm trying to run the angular demos but on both of them I get the following error

Error: this.audio is undefined
FlashAudioPlayer.prototype.play@file:///home/lucy/Downloads/audio5js-master/src/audio5.js:430
Audio5js.prototype.play@file:///home/lucy/Downloads/audio5js-master/src/audio5.js:828
Audio5js.prototype.playPause@file:///home/lucy/Downloads/audio5js-master/src/audio5.js:843
Mc/u/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js:70
dc[c]</</</<@http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js:141
Sc/this.$get</e.prototype.$eval@http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js:86
Sc/this.$get</e.prototype.$apply@http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js:86
dc[c]</</<@http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js:140
pc/c/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js:22
m@http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js:6
pc/c@http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js:22
"

Also on a side note is there anyway to state that you don't want a flash fallback?

Thanks

Stop method

Please add .stop() method.
Need to play online radio

duration is broken

Hi!

I'm trying to retrieve the duration of a track, following the Mobile Safari usage pattern.

Inside a canplay event callback i access player.duration property, and it always returns 0.

From play button click callback, the player.duration is 0 for the first time and 30.000181 on subsequent tries, which seems to be the correct value.

But i've also seen player.duration return 0:30 and NaN:NaN.

dafuq

play() can only run once in safari without quicktime

this is a simple html:

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
      <script src="js/audio5.js"></script>
      <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
    </head>

    <body>
      <button id="play">play</button>



      <script type="text/javascript">
        $(document).ready(function(){
          var audio5js = new Audio5js({
            swf_path: 'swf/audio5js.swf',
            ready: function () {
              this.load('sample3.mp3');
            }
          });


          $("#play").click(function(){
           audio5js.play();
         });

        });
      </script>
    </body>

    </html>

I open it in safari without quicktime on my pc(so the mp3 will play with audio5js.swf, I think), and I click the play button, the mp3 will play, it works. But when I press the button again, it is no sound.

I open this html with firefox and ie, audio5js works well.

what's wrong? it seems like the swf is not correct run at the second time.

`this.seek()` function doesnt work!

Hi,
i using BackboneJS for build a web audio player with this library,
i write a method for move to start:

stopMusic: function () {
    if (this.playing) {
        this.seek(0)
    }
}

and its doesnt work! but everything like this.pause(); method works fine! but this.seek(0); doesnt! and there is no error in console.

Seek function doesn't work on flash engine

Nice work zohararad ! That's a really great cross navigator player !

But I think I found a bug : the seek function for flash player doesn't seem to work

seek: function (position) {
      try {
        this.audio.seekTo(position);
        this.position = position;
      } catch (e) {}
    }

on line 387
it catches an exception when. Works well for html engine :)

Flash container inserted too soon

The element containing the flash embed code is tried appended to document.body at a time when document.body may not be set (depending on when audiojs is initialized).

I.e. the following will break flash fallback:

<html>
<head>
  <script src="/js/audio5.js"></script>
  <script>
    function initAudio () {
      var audio5js = new Audio5js({
        ready: function () {
          this.load('/someaudio.mp3');
          this.play();
        }
     });
    }
    initAudio();
  </script>
  </head>
<body>
(...)

Offending line is this: zohararad/audio5js/src/audio5.js#L209

Format Duration not working

I'm using audio5js with angular and for some reason format_time only affects position but duration always remains unformatted in seconds. Also i've checked all the demos for ngAudio and they all seem to have the same problem.

mp4 codec support seems to have problem

I have this piece of coffeescript

    @audio5js = new Audio5js
      codecs: ['mp4', 'vorbis', 'mp3']
      ready: (player) ->
        src = switch player.codec
          when 'mp4' then m4aSrc
          when 'vorbis' then ogaSrc
          else mp3Src
        @load(src)

The m4aSrc is an audio of .aac extension. When I try to execute this in chrome, Audio5js goes to mp4 source, load the aac file and then complain AUDIO_FORMAT_NOT_SUPPORTED.

playing more title on one page

i am trying to play more sounds on one page, one plays it means stop the before sound

but, i think that problem is that it takes some time when the playback is stopped, and new playback is stopped before it starts because i think that the new load is stopped due to before stop command

hope it is understandable?

or do you have some example how to do it?

´´´
(function ($) {
$.extend({
soundsplayer: {
audio5: null,
audioStopping: false,
elem: null,
playsoundtimeElem: null,
init: function() {
var self = this;

            self.audio5 = new Audio5js({
                        swf_path: '/swf/audio5/audio5js.swf',
                        throw_errors: true,
                        format_time: true,
                        ready: function(player) {

                            this.on('ended', $.soundsplayer.audioStop, this);

                            this.on('progress', function(load_percent) {
                                $.soundsplayer.progressupdate(load_percent);
                            }, self);

                            this.on('timeupdate', function(position, duration) {
                                $.soundsplayer.timeupdate(position);
                            }, this);

                            $(document).on('click', 'i.playsound', $.soundsplayer.play);
                            $(document).on('click', 'i.playsoundstop', $.soundsplayer.stop);
                        }
                    });
        },

        timeupdate: function(position) {
            $.soundsplayer.playsoundtimeElem.html(position);
        },

        progressupdate: function(loadPercent) {
            $.soundsplayer.playsoundtimeElem.html(loadPercent + "%");
        },

        audioEnded: function(e) {
            $.soundsplayer.audioEnding = false;
            $.soundsplayer.audioEnded = true;
        },          

        play: function(e) {
            console.log("play");
            console.log(e);

            var audio5 = $.soundsplayer.audio5;
            console.log($.soundsplayer.elem);

            // nejdrive zastavime bezici playback
            if (audio5.playing || $.soundsplayer.elem) {
                // vyhodime z teto funkce
                $.soundsplayer.stop();                  
                $.soundsplayer.play(e);
            }
            else {              
                console.log("jedu");
                var elem = $(this);
                $.soundsplayer.elem = elem;
                //console.log($.soundsplayer.elem);

                var parent = elem.parent();
                $.soundsplayer.playsoundtimeElem = $($(parent).find('.playsoundtime')[0]);
                //console.log($.soundsplayer.playsoundtimeElem);

                // zamen play za stop
                elem.removeClass('playsound');
                elem.removeClass('fa-play');
                elem.addClass('playsoundstop fa-stop');

                var url = elem.data('stream');              
                console.log(url);
                audio5.load(url);
                audio5.play();
                audio5.volume(1);
            }
        },

        stop: function(e) {
            console.log("stop");
            console.log(e);

            var elem = $.soundsplayer.elem;             
            // zamen stop za play
            elem.removeClass('playsoundstop');
            elem.removeClass('fa-stop');
            elem.addClass('playsound fa-play');

            var playsoundtimeElem = $.soundsplayer.playsoundtimeElem;
            playsoundtimeElem.html("");

            $.soundsplayer.elem = null;
            $.soundsplayer.playsoundtimeElem = null;

            console.log("porad stop stop");
            console.log($.soundsplayer.elem);

            $.soundsplayer.audioEnding = true;
            $.soundsplayer.audioEnded = false;              

            var audio5 = $.soundsplayer.audio5;
            console.log(audio5);
            audio5.seek(0);
            audio5.pause();
        }
    }
});

})(jQuery);

´´´

destroyAudio doesn't stop audio

I'm looking for a way to stop the audio from playing as well as downloading in the background. I found the destroyAudio method but it simply deletes the instance which doesn't stop the audio, at least in my version of chrome. Currently, I'm nulling the audio src which creates an uncaught error.

Single audio

I want when hover the menu list to play only the current sound.
It's possible to stopallsounds?

$('.cms39_accessibility_hover ').mouseover(function (e) {
        var text = $(this).text();
        var tts ='source'; 
        initAudio(tts);
    });

function initAudio(tts) {
    var audio5js = new Audio5js({
        swf_path: 'http://cdn.jsdelivr.net/audio5js/0.1.7/swf/audio5js.swf',
        ready: function () {
            this.load(tts);
            this.play();
        }
    });
    //audio.destroy();
}

Cannot Unsubscribe from Event from within Handler

Calling Pubsub#off is no-op while Pubsub#trigger is running:

function handler() {
  if (...) {
    player.off('progress', handler)
  }
})

player.on('progress', handler)

This happens since trigger empties the channels array while processing event handlers. So the handler does not appear to be registered while trigger is running.

In most cases you can probably just use one instead. Still, it's a gotcha.

Audio5js on mobile browsers

Hi, I'd like to use audio5js on a playlist-site (hvsr.net) but I'm experiencing some problems on mobile browsers. I know Apple and Android won't allow the autoplay feature, and it's ok for me to have the playlist streamed only after the user plays the PLAY button. BUT I would like the player to stream a new song when the previous one has ended. On desktop it works, but not on mobile. Please take a look at this demo page:
http://jsfiddle.net/franz976/pyt5k0ma/

thank you

Position is 0 after Seek, then Play.

Hi, I can play() an mp3 file, then seek(), and monitor it's position using the timeupdate event. This works as expected.

My problem is the position returns to 0 when I do this process:

1: pause()
2: seek(position + 0.5) // advance the position 1/2 second
3: play()

Imagine the position at 1 is 10 seconds and duration is 20 seconds. After step 2, the position pointer is 10.5 seconds, then, on step 3, the position should remain there, but it returns to 0. Is this a bug?.

the demos doesn't work

the demos doesn't work actually on both IE10 and chrome, by the way, is there anything special in contrast with audioJS ?

Parameters are reverse

this.on('timeupdate', function (duration, position) {
console.log(duration, position);
}, this);

// position, duration

Should output

//duration, position

html5 audio player for mp3 issue for Chrome

util.can_play()

returns false for mime_type:mp3, mime_str :audio/mpeg; codecs="mp3".

!!a.canPlayType && a.canPlayType(mime_str) !== ''

returns false.

tested this on chrome 36.0.1985.125, android chrome. Does not happen on Safari. The interesting thing is if you change the mime_str for mp3 to audio/mpeg; codec="mp3" it seems to be working.

Opera : Error: Cannot convert 'this.audio' to object

Hi,
Just tested my project in Opera Browser v12.16, i have this error:

Error: Cannot convert 'this.audio' to object
([arguments not available]) audio5.js:430
([arguments not available]) audio5.js:825

Hope this helps fix this issue

Thanks

Regards

Multiple players

Hey pal,

Thanks for this great lib, it is exactly what I was looking for..

But, I need 2 simultaneous audio players on my APP. For this I was creating 2 instances of Audio5js object, and here is the problem: Apparently the two instances uses the same 'HTML Audio' object, therefore, they are loading and playing exactly the same file.

Maybe this is occuring by my mistake, or maybe isn't your objective to have a multi instance player, but if can review this error, I'll be thankful.

Best regards

Audio5js's Flash cuts during a song

Hi,

This problem only happens in Firefox with Flash Player, HTML5 in IE10 works just fine.

At 2:29 of this song: http://www62.zippyshare.com/v/91387527/file.html, when using audio5js.min.js's seek function, the song finishes, cutting out the ending of the song (it should be 3:08 mins long). It's happened to quite a few songs. If you need more examples, just ask. If I don't use the seek function it will play the entire song to the ending, so it seems to be a problem with the seek function.

Thanks.

Legal disclaimer: I don't own that song, it's download may be used for research/educational purposes only.

Android Support

Wonderful work so far! You are AWESOME! It does not work in Android (namely, on my HTC Desire Z Android 2.3 Phone) but there is good news. There are two ways to workaround the missing audio tag support on older android devices:

Apparently this works, as silly as is looks:
[video src="test.mp3" onclick="this.play();"][/video]
Yes, as video. =) But I'm sot sure if this is of any help.

Additionally, Flash sound using mp3s also works great. An example of a functional implementation is the one found in SoundManager2 which I've successfully used on my phone.

More info here, including alternate workarounds:
http://stackoverflow.com/questions/3069124/playing-html5-audio-in-android-browser

Keep up the fantastic work, and know that your efforts are appreciated and highly valued. Thank you.

Audio won't play twice in chrome

Hi,
I'm having the following problem: when playing an audio file in chrome, it will play/pause correctly, but once I reach the 'ended' state, the file won't play again (I can't reach the .on('timeupdate' ...) method). This doesn't happen on Firefox, and I'm supposing the navigator must reload the audio file each time I press the play button.
Forcing the load in the on('play'...) method, I then am unable to pause the track, which is also the problem in Firefox.
I'm using AngularJS, and have tried including the ngAudio5.js module, but it doesn't seem to help. Have I forgotten to do something?

support dataURI scheme in Flash

audio5.load('http://127.0.0.1/test.mp3'); work well. But audio5.load("data:audio/mp3;base64,XXXXXXXXXXXX"); generate Error calling method on NPObject!

Is it be possible to use an audio file encoded in base64 ? How ?
Thank

Flash timeupdate frequence

Hi,
It seems timeupdate from the flash player isn't really acurate :
In the beginning of the song, the duration varies during 5-10 secs before it stabilizes

Moreover sometimes it seems, that it is possible to break the flash module. It stops sending event and it cannot be controled anymore. It happens when there are errors on the callbacks listenings to events for exemple. And more strangely firefox doesn't fires errors when there are errors in the listeners functions

I'm using Firefox 18 for my tests.

Thanks

IE11 on Windows 7 - 'play' event only fires once

It appears that IE11 on Windows 7 only fires the 'play' event when you first play the audio. If you have the audio play more than once, it no longer broadcasts a play event which breaks the tracking of play / pause in audiojs.

My workaround solution was to replace the 'play' listener with 'playing'. IE11 appears to fire this event every time audio.play() is called. Chrome and Firefox also work with using the 'playing' event.

Audio5js no longer playing after updating to latest Chrome 36.0.1985.125

After updating the the latest version of Chrome (36.0.1985.125) I'm getting the following error:

TypeError: Cannot read property 'pplay' of undefined
at Object.FlashAudioPlayer.play (http://localhost:9000/components/audio5js/audio5.js:433:17)
at Object.Audio5js.play (http://localhost:9000/components/audio5js/audio5.js:835:20)
at Object.Audio5js.playPause (http://localhost:9000/components/audio5js/audio5.js:850:44)
at http://localhost:9000/bower_components/angular/angular.js:10773:21
at http://localhost:9000/bower_components/angular/angular.js:18981:17
at Scope.$eval (http://localhost:9000/bower_components/angular/angular.js:12608:28)
at Scope.$apply (http://localhost:9000/bower_components/angular/angular.js:12706:23)
at HTMLSpanElement. (http://localhost:9000/bower_components/angular/angular.js:18980:21)
at HTMLSpanElement.jQuery.event.dispatch (http://localhost:9000/bower_components/jquery/dist/jquery.js:4641:9)
at HTMLSpanElement.elemData.handle (http://localhost:9000/bower_components/jquery/dist/jquery.js:4309:46)

No issue with latest versions of Firefox and Safari. Seems to do something with incorrectly falling back to flash instead of using HTML5 audio?

Excellent audio player, hopefully this can be figured out soon.

Internet Explorer 8 and 9 "Script Not Implemented" on 'Quick Demo' page

Unfortunately Audio5js does not load in Internet Explorer 8 and 9 (at least) on this page http://zohararad.github.io/audio5js/ (and in my usage scenario with same error).

IE console says:

SCRIPT16385: Not implemented

audio5.min.js, line 2 character 1979
SCRIPT5009: 'Audio5js' is undefined
audio5js, line 450 character 7

When I click on "Load Audio" then nothing happens, text does not change and control elements do not load like they do on other browsers.

Thought I would highlight this since docs said it was tested on IE8+, hopefully it is an easy issue to fix.

Volume on Safari Mobile

Setting the volume doesn't seem to be working on Safari Mobile. My code works fine on desktop browsers (Tested with chrome and safari), but the same code doesn't work on Safari iOS7.

Cannot play MP3 file from blob in Firefox

I was trying to play an MP3 file on Firefox, loading it as a blob.

player = new Audio5js({swf_path: "swf/audio5js.swf", throw_errors: true, format_time: false});
player.load('blob:2f927413-235d-c540-8c74-32425c1cc4b5')
player.play()

This doesn't play the blob and throws an error:
Error: Error in Actionscript. Use a try/catch block to find error.

The same works on Chrome, as it uses the HTML5 audio player, but since Firefox HTML5 audio doesn't support MP3, it falls back to the SWF player. It seems the SWF player has a problem playing blobs. Is this something that you would be able to fix?

How to integrate with backbone js

Could you please help me integrate audio5js with backbone js. I am using handlebars templates, i need to put audio to my backbone view, as internet explorer wont play .wav files.

Sorry, this is not an issue, was just asking a help :) .

Best Regards,
Deepu.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.