「この曲なに?」カードを表示する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
音声を再生する TV アプリは、ユーザーがホーム画面に戻った後も引き続き再生する場合がある。
別のアプリに切り替える。そのためには、アプリの家に [この曲なに?] カードが表示される必要があります。
表示されます。このカードにより、ユーザーは音声の出所を把握し、アプリに戻ってきて
メディアの再生を操作する。
アクティブな
MediaSession
は
Android フレームワークでは、ホーム画面に [この曲なに?] カードが表示されます。カード
アルバムアート、タイトル、アプリアイコンなどのメディアのメタデータが含まれます。ユーザーがカードを選択すると
システムがアプリを起動します。
「この曲なに?」カード
メディア セッションを実装したら、
音声フォーカスをリクエストすると、[この曲なに?] カードが表示されます。
注: [この曲なに?] カードはメディアについてのみ表示されます。
セッションを
FLAG_HANDLES_TRANSPORT_CONTROLS
設定されます。このフラグは API レベル 26 で非推奨になりました。ただし、下位互換性のために、古いデバイスではこのフラグが引き続き必要になることがあります。
カードは、ランチャー画面から
setActive(false)
呼び出しはメディア セッションを無効にするか、別のアプリがメディアの再生を開始したときに無効にします。再生が
完全に停止してアクティブなメディアがない場合は、メディア セッションを無効にします
すぐに通知されます。再生が一時停止した場合は、しばらく待ってからメディア セッションを無効にします。
通常は 5 ~ 30 分です。
カードを更新する
アプリが MediaSession
の再生状態を更新するたびに、
[この曲なに?] カードが更新され、現在のメディアの状態が表示されます。方法については、
再生状態を更新する。
同様に、アプリで
MediaMetadata
: 提供
[この曲なに?] カードに、現在のメディアに関する情報(タイトル、サブタイトル、
さまざまなアイコンがあります方法については、
メディア メタデータを更新します。
ユーザー アクションに応答する
ユーザーが [この曲なに?] カードを選択すると、
あります。アプリが
PendingIntent
~
setSessionActivity()
,
システムは、次のコード スニペットに示すように、指定したアクティビティを起動します。そうでない場合
デフォルトのシステム インテントが開きます。指定するアクティビティでは、ユーザーが操作できる再生コントロールを
ユーザーが再生を一時停止または停止できるようにします
Kotlin
val pi: PendingIntent = Intent(context, MyActivity::class.java).let { intent ->
PendingIntent.getActivity(
context, 99 /*request code*/,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
)
}
session.setSessionActivity(pi)
Java
Intent intent = new Intent(context, MyActivity.class);
PendingIntent pi = PendingIntent.getActivity(context, 99 /*request code*/,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
session.setSessionActivity(pi);
受け入れられるユースケース
「この曲なに?」カードは、音声の続きをユーザーが期待している場合のみ使用してください。
バックグラウンドで再生されるモードです。ゲームの動画の再生や音声は、
アプリがピクチャー イン ピクチャーに統合され、準拠している場合を除き、一時停止します。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-27 UTC。
[null,null,["最終更新日 2025-07-27 UTC。"],[],[],null,["# Display a Now Playing card\n\nTV apps that play audio may continue to do so after the user returns to the home screen or\nswitches to another app. To do so, the app must provide a **Now Playing** card on the home\nscreen. This card lets users understand where the audio is coming from and return to your app to\ncontrol media playback.\n\n\nWhenever an active\n[MediaSession](/reference/android/media/session/MediaSession) is\npresent, the Android framework displays a **Now Playing** card on the home screen. The card\nincludes media metadata such as album art, title, and app icon. When the user selects the card,\nthe system opens the app.\n\nNow Playing card\n----------------\n\n\nAfter you [implement a media session](/training/tv/playback/media-session), set the\nsession to active, and request audio focus, the **Now Playing** card appears.\n\n**Note:** The **Now Playing** card displays only for a media\nsession with the\n[FLAG_HANDLES_TRANSPORT_CONTROLS](/reference/android/media/session/MediaSession#FLAG_HANDLES_TRANSPORT_CONTROLS)\nflag set. This flag is deprecated on API level 26. However, this flag could still be needed on older devices for backwards compatibility.\n\n\nThe card is removed from the launcher screen when a\n[setActive(false)](/reference/android/media/session/MediaSession#setActive(boolean))\ncall deactivates the media session or when another app initiates media playback. If playback is\ncompletely stopped and there is no active media, deactivate the media session\nimmediately. If playback is paused, deactivate the media session after a delay,\nusually from 5 to 30 minutes.\n\nUpdate the card\n---------------\n\n\nWhenever your app updates the playback state in the `MediaSession`, the\n**Now Playing** card updates to show the state of the current media. To learn how to do this, see\n[Update the playback state](/training/tv/playback/media-session#state).\n\n\nSimilarly, your app can update the\n[MediaMetadata](/reference/android/media/MediaMetadata) to provide\ninformation to the **Now Playing** card about the current media, such as the title, subtitle,\nand various icons. To learn how to do this, see\n[Update the media metadata](/training/tv/playback/media-session#metadata).\n\nRespond to user action\n----------------------\n\n\nWhen the user selects the **Now Playing** card, the system opens the app that owns the\nsession. If your app provides a\n[PendingIntent](/reference/android/app/PendingIntent) to\n[setSessionActivity()](/reference/android/media/session/MediaSession#setSessionActivity(android.app.PendingIntent)),\nthe system launches the activity you specify, as shown in the following code snippet. If not,\nthe default system intent opens. The activity you specify must provide playback controls that\nlet users pause or stop playback. \n\n### Kotlin\n\n```kotlin\nval pi: PendingIntent = Intent(context, MyActivity::class.java).let { intent -\u003e\n PendingIntent.getActivity(\n context, 99 /*request code*/,\n intent,\n PendingIntent.FLAG_UPDATE_CURRENT\n )\n}\nsession.setSessionActivity(pi)\n```\n\n### Java\n\n```java\nIntent intent = new Intent(context, MyActivity.class);\nPendingIntent pi = PendingIntent.getActivity(context, 99 /*request code*/,\n intent, PendingIntent.FLAG_UPDATE_CURRENT);\nsession.setSessionActivity(pi);\n```\n\nAccepted use cases\n------------------\n\n\nThe **Now Playing** card should only be used in cases where the user expects audio to continue\nplaying in the background when leaving your app. Video playback or sound from a game should always\npause, unless your app is integrating and compliant with picture-in-picture."]]