Commit 395240b4 authored by hirono's avatar hirono Committed by Commit bot

Files.app: Start to use new metadata model in Audio Player.

BUG=410766
TEST=None

Review URL: https://codereview.chromium.org/936243004

Cr-Commit-Position: refs/heads/master@{#317019}
parent d26db642
...@@ -24,19 +24,30 @@ ...@@ -24,19 +24,30 @@
<!-- Keep the list in sync with audio_player_scripts.js. --> <!-- Keep the list in sync with audio_player_scripts.js. -->
<script src="../../webui//resources/js/cr.js"></script> <script src="../../webui//resources/js/cr.js"></script>
<script src="../../webui/resources/js/cr/event_target.js"></script> <script src="../../webui/resources/js/cr/event_target.js"></script>
<script src="../../webui/resources/js/cr/ui/array_data_model.js"> <script src="../../webui/resources/js/cr/ui/array_data_model.js"></script>
</script>
<script src="../../../third_party/polymer/polymer/polymer.js"></script> <script src="../../../third_party/polymer/polymer/polymer.js"></script>
<!-- Base classes. -->
<script src="../file_manager/foreground/js/metadata/metadata_cache_set.js"></script>
<script src="../file_manager/foreground/js/metadata/new_metadata_provider.js"></script>
<script src="../file_manager/common/js/async_util.js"></script> <script src="../file_manager/common/js/async_util.js"></script>
<script src="../file_manager/common/js/file_type.js"></script> <script src="../file_manager/common/js/file_type.js"></script>
<script src="../file_manager/common/js/util.js"></script> <script src="../file_manager/common/js/util.js"></script>
<script src="../file_manager/common/js/volume_manager_common.js"></script> <script src="../file_manager/common/js/volume_manager_common.js"></script>
<script src="../file_manager/foreground/js/volume_manager_wrapper.js"></script> <script src="../file_manager/foreground/js/volume_manager_wrapper.js"></script>
<script src="../file_manager/foreground/js/metadata/metadata_cache.js"></script>
<script src="../file_manager/foreground/js/metadata/content_metadata_provider.js"></script>
<script src="../file_manager/foreground/js/metadata/external_metadata_provider.js"></script>
<script src="../file_manager/foreground/js/metadata/file_system_metadata.js"></script>
<script src="../file_manager/foreground/js/metadata/file_system_metadata_provider.js"></script>
<script src="../file_manager/foreground/js/metadata/metadata_cache_item.js"></script>
<script src="../file_manager/foreground/js/metadata/metadata_item.js"></script>
<script src="../file_manager/foreground/js/metadata/thumbnail_model.js"></script>
<script src="js/audio_player.js"></script> <script src="js/audio_player.js"></script>
<script src="js/audio_player_model.js"></script>
<script src="elements/track_list.js"></script> <script src="elements/track_list.js"></script>
<script src="elements/control_panel.js"></script> <script src="elements/control_panel.js"></script>
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* @type {string} * @type {string}
* @const * @const
*/ */
ContentProvider.WORKER_SCRIPT = '/js/metadata_worker.js'; ContentMetadataProvider.WORKER_SCRIPT = '/js/metadata_worker.js';
/** /**
* @param {HTMLElement} container Container element. * @param {HTMLElement} container Container element.
...@@ -17,7 +17,8 @@ function AudioPlayer(container) { ...@@ -17,7 +17,8 @@ function AudioPlayer(container) {
this.container_ = container; this.container_ = container;
this.volumeManager_ = new VolumeManagerWrapper( this.volumeManager_ = new VolumeManagerWrapper(
VolumeManagerWrapper.DriveEnabledStatus.DRIVE_ENABLED); VolumeManagerWrapper.DriveEnabledStatus.DRIVE_ENABLED);
this.metadataCache_ = MetadataCache.createFull(this.volumeManager_); this.fileSystemMetadata_ = FileSystemMetadata.create(
new MetadataProviderCache(), this.volumeManager_);
this.selectedEntry_ = null; this.selectedEntry_ = null;
this.model_ = new AudioPlayerModel(); this.model_ = new AudioPlayerModel();
...@@ -72,7 +73,7 @@ function AudioPlayer(container) { ...@@ -72,7 +73,7 @@ function AudioPlayer(container) {
* Initial load method (static). * Initial load method (static).
*/ */
AudioPlayer.load = function() { AudioPlayer.load = function() {
document.ondragstart = function(e) { e.preventDefault() }; document.ondragstart = function(e) { e.preventDefault(); };
AudioPlayer.instance = AudioPlayer.instance =
new AudioPlayer(document.querySelector('.audio-player')); new AudioPlayer(document.querySelector('.audio-player'));
...@@ -237,11 +238,12 @@ AudioPlayer.prototype.select_ = function(newTrack, time) { ...@@ -237,11 +238,12 @@ AudioPlayer.prototype.select_ = function(newTrack, time) {
* @private * @private
*/ */
AudioPlayer.prototype.fetchMetadata_ = function(entry, callback) { AudioPlayer.prototype.fetchMetadata_ = function(entry, callback) {
this.metadataCache_.getOne(entry, 'thumbnail|media|external', this.fileSystemMetadata_.get(
[entry], ['mediaTitle', 'mediaArtist', 'present']).then(
function(generation, metadata) { function(generation, metadata) {
// Do nothing if another load happened since the metadata request. // Do nothing if another load happened since the metadata request.
if (this.playlistGeneration_ == generation) if (this.playlistGeneration_ == generation)
callback(metadata); callback(metadata[0]);
}.bind(this, this.playlistGeneration_)); }.bind(this, this.playlistGeneration_));
}; };
...@@ -257,7 +259,7 @@ AudioPlayer.prototype.onError_ = function() { ...@@ -257,7 +259,7 @@ AudioPlayer.prototype.onError_ = function() {
this.fetchMetadata_( this.fetchMetadata_(
this.entries_[track], this.entries_[track],
function(metadata) { function(metadata) {
var error = (!navigator.onLine && !metadata.external.present) ? var error = (!navigator.onLine && !metadata.present) ?
this.offlineString_ : this.errorString_; this.offlineString_ : this.errorString_;
this.displayMetadata_(track, metadata, error); this.displayMetadata_(track, metadata, error);
this.scheduleAutoAdvance_(); this.scheduleAutoAdvance_();
...@@ -389,7 +391,7 @@ AudioPlayer.TrackInfo = function(entry, onClick) { ...@@ -389,7 +391,7 @@ AudioPlayer.TrackInfo = function(entry, onClick) {
/** /**
* @return {HTMLDivElement} The wrapper element for the track. * @return {HTMLDivElement} The wrapper element for the track.
*/ */
AudioPlayer.TrackInfo.prototype.getBox = function() { return this.box_ }; AudioPlayer.TrackInfo.prototype.getBox = function() { return this.box_; };
/** /**
* @return {string} Default track title (file name extracted from the url). * @return {string} Default track title (file name extracted from the url).
...@@ -422,10 +424,8 @@ AudioPlayer.TrackInfo.prototype.setMetadata = function( ...@@ -422,10 +424,8 @@ AudioPlayer.TrackInfo.prototype.setMetadata = function(
metadata, error) { metadata, error) {
// TODO(yoshiki): Handle error in better way. // TODO(yoshiki): Handle error in better way.
// TODO(yoshiki): implement artwork (metadata.thumbnail) // TODO(yoshiki): implement artwork (metadata.thumbnail)
this.title = (metadata.media && metadata.media.title) || this.title = metadata.mediaTitle || this.getDefaultTitle();
this.getDefaultTitle(); this.artist = error || metadata.mediaArtist || this.getDefaultArtist();
this.artist = error ||
(metadata.media && metadata.media.artist) || this.getDefaultArtist();
}; };
// Starts loading the audio player. // Starts loading the audio player.
......
...@@ -23,12 +23,23 @@ Object['observe'] = undefined; ...@@ -23,12 +23,23 @@ Object['observe'] = undefined;
// 'strict mode' is invoked for this scope. // 'strict mode' is invoked for this scope.
'use strict'; 'use strict';
// Base classes.
<include src="../../file_manager/foreground/js/metadata/metadata_cache_set.js">
<include src="../../file_manager/foreground/js/metadata/new_metadata_provider.js">
<include src="../../file_manager/common/js/async_util.js"/> <include src="../../file_manager/common/js/async_util.js"/>
<include src="../../file_manager/common/js/file_type.js"/> <include src="../../file_manager/common/js/file_type.js"/>
<include src="../../file_manager/common/js/util.js"/> <include src="../../file_manager/common/js/util.js"/>
<include src="../../file_manager/common/js/volume_manager_common.js"/> <include src="../../file_manager/common/js/volume_manager_common.js"/>
<include src="../../file_manager/foreground/js/volume_manager_wrapper.js"> <include src="../../file_manager/foreground/js/volume_manager_wrapper.js">
<include src="../../file_manager/foreground/js/metadata/metadata_cache.js"/>
<include src="../../file_manager/foreground/js/metadata/content_metadata_provider.js">
<include src="../../file_manager/foreground/js/metadata/external_metadata_provider.js">
<include src="../../file_manager/foreground/js/metadata/file_system_metadata.js">
<include src="../../file_manager/foreground/js/metadata/file_system_metadata_provider.js">
<include src="../../file_manager/foreground/js/metadata/metadata_cache_item.js">
<include src="../../file_manager/foreground/js/metadata/metadata_item.js">
<include src="../../file_manager/foreground/js/metadata/thumbnail_model.js">
<include src="audio_player.js"/> <include src="audio_player.js"/>
<include src="audio_player_model.js"/> <include src="audio_player_model.js"/>
......
...@@ -77,7 +77,9 @@ ContentMetadataProvider.convertContentMetadata = function(metadata) { ...@@ -77,7 +77,9 @@ ContentMetadataProvider.convertContentMetadata = function(metadata) {
var item = new MetadataItem(); var item = new MetadataItem();
item.contentThumbnailUrl = metadata['thumbnailURL']; item.contentThumbnailUrl = metadata['thumbnailURL'];
item.contentThumbnailTransform = metadata['thumbnailTransform']; item.contentThumbnailTransform = metadata['thumbnailTransform'];
item.contentImageTransform = metadata ['imageTransform']; item.contentImageTransform = metadata['imageTransform'];
item.mediaTitle = metadata['title'];
item.mediaArtist = metadata['artist'];
return item; return item;
}; };
...@@ -190,10 +192,11 @@ ContentMetadataProvider.prototype.onResult_ = function(url, metadata) { ...@@ -190,10 +192,11 @@ ContentMetadataProvider.prototype.onResult_ = function(url, metadata) {
* @param {Object?} metadata The metadata, if available. * @param {Object?} metadata The metadata, if available.
* @private * @private
*/ */
ContentMetadataProvider.prototype.onError_ = ContentMetadataProvider.prototype.onError_ = function(
function(url, step, error, metadata) { url, step, error, metadata) {
if (MetadataCache.log) // Avoid log spam by default. console.error(
console.warn('metadata: ' + url + ': ' + step + ': ' + error); 'ContentMetadataProvider failed to obtain metadata: '+
url + ': ' + step + ': ' + error);
this.onResult_(url, new MetadataItem()); this.onResult_(url, new MetadataItem());
}; };
...@@ -203,6 +206,5 @@ ContentMetadataProvider.prototype.onError_ = ...@@ -203,6 +206,5 @@ ContentMetadataProvider.prototype.onError_ =
* @private * @private
*/ */
ContentMetadataProvider.prototype.onLog_ = function(arglist) { ContentMetadataProvider.prototype.onLog_ = function(arglist) {
if (MetadataCache.log) // Avoid log spam by default. console.log.apply(console, ['ContentMetadataProvider log:'].concat(arglist));
console.log.apply(console, ['metadata:'].concat(arglist));
}; };
...@@ -80,7 +80,7 @@ MetadataDispatcher.prototype.init_ = function() { ...@@ -80,7 +80,7 @@ MetadataDispatcher.prototype.init_ = function() {
// Inform our owner that we're done initializing. // Inform our owner that we're done initializing.
// If we need to pass more data back, we can add it to the param array. // If we need to pass more data back, we can add it to the param array.
this.postMessage('initialized', [this.parserRegexp_]); this.postMessage('initialized', [this.parserRegexp_]);
this.log('initialized with URL filter ' + this.parserRegexp_); this.vlog('initialized with URL filter ' + this.parserRegexp_);
}; };
/** /**
...@@ -199,13 +199,13 @@ MetadataDispatcher.prototype.processOneFile = function(fileURL, callback) { ...@@ -199,13 +199,13 @@ MetadataDispatcher.prototype.processOneFile = function(fileURL, callback) {
function getEntry(parser) { function getEntry(parser) {
webkitResolveLocalFileSystemURL( webkitResolveLocalFileSystemURL(
fileURL, fileURL,
function(entry) { nextStep(entry, parser) }, function(entry) { nextStep(entry, parser); },
onError); onError);
}, },
// Step three, turn the entry into a file. // Step three, turn the entry into a file.
function getFile(entry, parser) { function getFile(entry, parser) {
entry.file(function(file) { nextStep(file, parser) }, onError); entry.file(function(file) { nextStep(file, parser); }, onError);
}, },
// Step four, parse the file content. // Step four, parse the file content.
......
...@@ -128,4 +128,14 @@ function MetadataItem() { ...@@ -128,4 +128,14 @@ function MetadataItem() {
* @public {string|undefined} * @public {string|undefined}
*/ */
this.externalFileUrl; this.externalFileUrl;
/**
* @public {string|undefined}
*/
this.mediaTitle;
/**
* @public {string|undefined}
*/
this.mediaArtist;
} }
...@@ -104,6 +104,7 @@ ...@@ -104,6 +104,7 @@
<!-- AudioPlayer.app pages and scripts. --> <!-- AudioPlayer.app pages and scripts. -->
<include name="IDR_AUDIO_PLAYER_MANIFEST" file="audio_player/manifest.json" type="BINDATA" /> <include name="IDR_AUDIO_PLAYER_MANIFEST" file="audio_player/manifest.json" type="BINDATA" />
<include name="IDR_AUDIO_PLAYER_BKGND_JS" file="audio_player/js/background.js" flattenhtml="true" type="BINDATA" /> <include name="IDR_AUDIO_PLAYER_BKGND_JS" file="audio_player/js/background.js" flattenhtml="true" type="BINDATA" />
<include name="IDR_AUDIO_PLAYER_METADATA_WORKER_JS" file="audio_player/js/metadata_worker.js" flattenhtml="true" type="BINDATA" />
<include name="IDR_AUDIO_PLAYER" file="audio_player/audio_player.html" allowexternalscript="true" flattenhtml="true" type="BINDATA" /> <include name="IDR_AUDIO_PLAYER" file="audio_player/audio_player.html" allowexternalscript="true" flattenhtml="true" type="BINDATA" />
<include name="IDR_AUDIO_PLAYER_JS" file="audio_player/js/audio_player_scripts.js" flattenhtml="true" type="BINDATA" /> <include name="IDR_AUDIO_PLAYER_JS" file="audio_player/js/audio_player_scripts.js" flattenhtml="true" type="BINDATA" />
<include name="IDR_AUDIO_PLAYER_ICON_FAVICON_16" file="audio_player/icons/audio-player-favicon-16.png" type="BINDATA" /> <include name="IDR_AUDIO_PLAYER_ICON_FAVICON_16" file="audio_player/icons/audio-player-favicon-16.png" type="BINDATA" />
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment