function open(urls) {
  var position = 0;
  var startUrl = (position < urls.length) ? urls[position] : '';

  return new Promise(function(fulfill, reject) {
    if (urls.length === 0) {
      reject('No file to open.');
      return;
    }

    // Gets the current list of the children of the parent.
    window.webkitResolveLocalFileSystemURL(urls[0], function(fileEntry) {
      fileEntry.getParent(function(parentEntry) {
        var dirReader = parentEntry.createReader();
        var entries = [];

        // Call the reader.readEntries() until no more results are returned.
        var readEntries = function() {
           dirReader.readEntries(function(results) {
            if (!results.length) {
              fulfill(entries.sort(util.compareName));
            } else {
              entries = entries.concat(Array.prototype.slice.call(results, 0));
              readEntries();
            }
          }, reject);
        };

        // Start reading.
        readEntries();
      }, reject);
    }, reject);
  }).then(function(entries) {
    // Omits non-audio files.
    var audioEntries = entries.filter(FileType.isAudio);

    // Adjusts the position to start playing.
    var maybePosition = util.entriesToURLs(audioEntries).indexOf(startUrl);
    if (maybePosition !== -1)
      position = maybePosition;

    // Opens the audio player.
    return new Promise(function(fulfill, reject) {
      var urls = util.entriesToURLs(audioEntries);
      audioPlayer.launch({items: urls, position: position},
                         false,
                         fulfill.bind(null, null));
    });
  }).then(function() {
    audioPlayer.setIcon(AUDIO_PLAYER_ICON);
    audioPlayer.rawAppWindow.focus();
    return AUDIO_PLAYER_APP_URL;
  }).catch(function(error) {
    console.error('Launch failed' + error.stack || error);
    return Promise.reject(error);
  });
}
/**
 * Opens the audio player window.
 * @param {!Array<string>} urls List of audios to play and index to start
 *     playing.
 * @return {!Promise} Promise to be fulfilled on success, or rejected on error.
 */
Opens the audio player window.
@param {!Array} urls List of audios to play and index to start
playing.
@return {!Promise} Promise to be fulfilled on success, or rejected on error.
Opens the audio player window . @param { !Array } urls List of audios to play and index to start playing . @return { !Promise } Promise to be fulfilled on success or rejected on error .
function open(urls) {
  var position = 0;
  var startUrl = (position < urls.length) ? urls[position] : '';
  return new Promise(function(fulfill, reject) {
    if (urls.length === 0) {
      reject('No file to open.');
      return;
    }
    window.webkitResolveLocalFileSystemURL(urls[0], function(fileEntry) {
      fileEntry.getParent(function(parentEntry) {
        var dirReader = parentEntry.createReader();
        var entries = [];
        var readEntries = function() {
           dirReader.readEntries(function(results) {
            if (!results.length) {
              fulfill(entries.sort(util.compareName));
            } else {
              entries = entries.concat(Array.prototype.slice.call(results, 0));
              readEntries();
            }
          }, reject);
        };
        readEntries();
      }, reject);
    }, reject);
  }).then(function(entries) {
    var audioEntries = entries.filter(FileType.isAudio);
    var maybePosition = util.entriesToURLs(audioEntries).indexOf(startUrl);
    if (maybePosition !== -1)
      position = maybePosition;
    return new Promise(function(fulfill, reject) {
      var urls = util.entriesToURLs(audioEntries);
      audioPlayer.launch({items: urls, position: position},
                         false,
                         fulfill.bind(null, null));
    });
  }).then(function() {
    audioPlayer.setIcon(AUDIO_PLAYER_ICON);
    audioPlayer.rawAppWindow.focus();
    return AUDIO_PLAYER_APP_URL;
  }).catch(function(error) {
    console.error('Launch failed' + error.stack || error);
    return Promise.reject(error);
  });
}
function open ( urls ) { var position = 0 ; var startUrl = ( position < urls . length ) ? urls [ position ] : '' ; return new Promise ( function ( fulfill , reject ) { if ( urls . length === 0 ) { reject ( 'No file to open.' ) ; return ; } window . webkitResolveLocalFileSystemURL ( urls [ 0 ] , function ( fileEntry ) { fileEntry . getParent ( function ( parentEntry ) { var dirReader = parentEntry . createReader ( ) ; var entries = [ ] ; var readEntries = function ( ) { dirReader . readEntries ( function ( results ) { if ( ! results . length ) { fulfill ( entries . sort ( util . compareName ) ) ; } else { entries = entries . concat ( Array . prototype . slice . call ( results , 0 ) ) ; readEntries ( ) ; } } , reject ) ; } ; readEntries ( ) ; } , reject ) ; } , reject ) ; } ) . then ( function ( entries ) { var audioEntries = entries . filter ( FileType . isAudio ) ; var maybePosition = util . entriesToURLs ( audioEntries ) . indexOf ( startUrl ) ; if ( maybePosition !== - 1 ) position = maybePosition ; return new Promise ( function ( fulfill , reject ) { var urls = util . entriesToURLs ( audioEntries ) ; audioPlayer . launch ( { items : urls , position : position } , false , fulfill . bind ( null , null ) ) ; } ) ; } ) . then ( function ( ) { audioPlayer . setIcon ( AUDIO_PLAYER_ICON ) ; audioPlayer . rawAppWindow . focus ( ) ; return AUDIO_PLAYER_APP_URL ; } ) . catch ( function ( error ) { console . error ( 'Launch failed' + error . stack || error ) ; return Promise . reject ( error ) ; } ) ; }
Opens the audio player window.
Opens the audio player window .
// Gets the current list of the children of the parent. // Call the reader.readEntries() until no more results are returned. // Start reading. // Omits non-audio files. // Adjusts the position to start playing. // Opens the audio player.