Commit c669d5ae authored by Tommy Steimel's avatar Tommy Steimel Committed by Commit Bot

System Media Controls: Add title/artist/album metadata on Mac

This CL adds media session metadata (title, artist, and album) to the
Now Playing Info Center when available.

Bug: 936513
Change-Id: Id95728fd4ad1a06b242f6596475315fa65ec913c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1902509Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Commit-Queue: Tommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713232}
parent dce1a62b
......@@ -24,6 +24,10 @@ class API_AVAILABLE(macos(10.12.2)) NowPlayingInfoCenterDelegate {
// Part of the implementation of SystemMediaControls.
void SetPlaybackStatus(SystemMediaControls::PlaybackStatus status);
void SetTitle(const base::string16& title);
void SetArtist(const base::string16& artist);
void SetAlbum(const base::string16& album);
void ClearMetadata();
private:
base::scoped_nsobject<NowPlayingInfoCenterDelegateCocoa>
......
......@@ -6,6 +6,7 @@
#import <MediaPlayer/MediaPlayer.h>
#include "base/strings/sys_string_conversions.h"
#include "components/system_media_controls/mac/now_playing_info_center_delegate_cocoa.h"
namespace system_media_controls {
......@@ -47,5 +48,24 @@ void NowPlayingInfoCenterDelegate::SetPlaybackStatus(
[now_playing_info_center_delegate_cocoa_ setPlaybackState:state];
}
void NowPlayingInfoCenterDelegate::SetTitle(const base::string16& title) {
[now_playing_info_center_delegate_cocoa_
setTitle:base::SysUTF16ToNSString(title)];
}
void NowPlayingInfoCenterDelegate::SetArtist(const base::string16& artist) {
[now_playing_info_center_delegate_cocoa_
setArtist:base::SysUTF16ToNSString(artist)];
}
void NowPlayingInfoCenterDelegate::SetAlbum(const base::string16& album) {
[now_playing_info_center_delegate_cocoa_
setAlbum:base::SysUTF16ToNSString(album)];
}
void NowPlayingInfoCenterDelegate::ClearMetadata() {
[now_playing_info_center_delegate_cocoa_ clearMetadata];
}
} // namespace internal
} // namespace system_media_controls
......@@ -18,6 +18,12 @@ API_AVAILABLE(macos(10.12.2))
// Called by the NowPlayingInfoCenterDelegateImpl to set metadata.
- (void)setPlaybackState:(MPNowPlayingPlaybackState)state;
- (void)setTitle:(NSString*)title;
- (void)setArtist:(NSString*)artist;
- (void)setAlbum:(NSString*)album;
// Sets all metadata to default values.
- (void)clearMetadata;
@end
......
......@@ -43,6 +43,26 @@
[self updateNowPlayingInfo];
}
- (void)setTitle:(NSString*)title {
[nowPlayingInfo_ setObject:title forKey:MPMediaItemPropertyTitle];
[self updateNowPlayingInfo];
}
- (void)setArtist:(NSString*)artist {
[nowPlayingInfo_ setObject:artist forKey:MPMediaItemPropertyArtist];
[self updateNowPlayingInfo];
}
- (void)setAlbum:(NSString*)album {
[nowPlayingInfo_ setObject:album forKey:MPMediaItemPropertyAlbumTitle];
[self updateNowPlayingInfo];
}
- (void)clearMetadata {
[self initializeNowPlayingInfoValues];
[self updateNowPlayingInfo];
}
- (void)initializeNowPlayingInfoValues {
[nowPlayingInfo_ setObject:[NSNumber numberWithDouble:0]
forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
......@@ -56,6 +76,7 @@
[nowPlayingInfo_ setObject:@"Chromium" forKey:MPMediaItemPropertyTitle];
#endif
[nowPlayingInfo_ setObject:@"" forKey:MPMediaItemPropertyArtist];
[nowPlayingInfo_ setObject:@"" forKey:MPMediaItemPropertyAlbumTitle];
}
- (void)updateNowPlayingInfo {
......
......@@ -38,12 +38,12 @@ class API_AVAILABLE(macos(10.12.2)) SystemMediaControlsMac
void SetIsPlayPauseEnabled(bool value) override;
void SetIsStopEnabled(bool value) override;
void SetPlaybackStatus(PlaybackStatus status) override;
void SetTitle(const base::string16& title) override {}
void SetArtist(const base::string16& artist) override {}
void SetAlbum(const base::string16& album) override {}
void SetTitle(const base::string16& title) override;
void SetArtist(const base::string16& artist) override;
void SetAlbum(const base::string16& album) override;
void SetThumbnail(const SkBitmap& bitmap) override {}
void ClearThumbnail() override {}
void ClearMetadata() override {}
void ClearMetadata() override;
void UpdateDisplay() override {}
private:
......
......@@ -58,5 +58,21 @@ void SystemMediaControlsMac::SetPlaybackStatus(PlaybackStatus status) {
now_playing_info_center_delegate_.SetPlaybackStatus(status);
}
void SystemMediaControlsMac::SetTitle(const base::string16& title) {
now_playing_info_center_delegate_.SetTitle(title);
}
void SystemMediaControlsMac::SetArtist(const base::string16& artist) {
now_playing_info_center_delegate_.SetArtist(artist);
}
void SystemMediaControlsMac::SetAlbum(const base::string16& album) {
now_playing_info_center_delegate_.SetAlbum(album);
}
void SystemMediaControlsMac::ClearMetadata() {
now_playing_info_center_delegate_.ClearMetadata();
}
} // namespace internal
} // namespace system_media_controls
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