コンテンツの録画をサポートする
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
TV 入力サービスを使用すると、ユーザーは
タイムシフト API。
タイムシフトを拡張する Android 7.0
ユーザーが複数の録画セッションを保存できるようにします
事前に録画を予約したり、視聴しながら録画を開始したりできます。
できます。システムで録音を保存すると、ユーザーはその録音のブラウジング、管理、
システムの TV アプリを使用して録画を再生します。
TV 入力サービスに録画機能を提供する場合は、
アプリが録画をサポートしていることをシステムに示すこと、
番組を録画し、発生したエラーを処理して伝達する機能
設定したり、録画したセッションを管理したりできます。
録画のサポートを示す
テレビ入力サービスが録画に対応していることをシステムに伝えるには、
サービス メタデータ XML ファイルの android:canRecord
属性
宛先 true
:
<tv-input xmlns:android="http://schemas.android.com/apk/res/android"
android:canRecord="true"
android:setupActivity="com.example.sampletvinput.SampleTvInputSetupActivity" />
サービス メタデータ ファイルの詳細については、このモジュールの
テレビ入力を宣言する
(マニフェスト内のサービス)をご覧ください。
または、次のコマンドを使用して、コードで録音のサポートを示すこともできます。
手順は次のとおりです。
- テレビ入力サービス:
onCreate()
新しい TvInputInfo
オブジェクトを作成し、
TvInputInfo.Builder
クラス。
- 新しい
TvInputInfo
オブジェクトを作成するときに、次の関数を呼び出します。
呼び出しの前に setCanRecord(true)
build()
の場合は、
サポートしています。
- 次の呼び出しを使用して、
TvInputInfo
オブジェクトをシステムに登録します。
TvInputManager.updateTvInputInfo()
。
セッションを録画する
TV 入力サービスが録画に対応していることを登録した後
機能すると、システムは
アクセスする必要がある場合に TvInputService.onCreateRecordingSession()
メソッドを
実装する必要があります。独自の実装
TvInputService.RecordingSession
サブクラスを作成してそれを返す
onCreateRecordingSession()
コールバックが発生したとき。このサブクラスは、
正しいチャンネル データへの切り替え、リクエストされたデータの記録、
記録ステータスやエラーのシステムへの
伝達が含まれます
システムが
RecordingSession.onTune()
、チャンネル URI を渡してチャンネルに合わせる
URI で指定されます。アプリが
チャネルを指定して
notifyTuned()
または、アプリで適切なチャンネルにチューニングできない場合は、
notifyError()
。
次に、システムは
RecordingSession.onStartRecording()
コールバック。アプリで録画を開始する必要があります
すぐに通知されます。システムはこのコールバックを呼び出すときに、URI を提供する場合があります。
録画しようとしている番組に関する情報が含まれています。
録画が完了したら、このデータを
RecordedPrograms
作成します
最後に、システムは
RecordingSession.onStopRecording()
。この時点でアプリは
すぐに録画を開始します。また、
RecordedPrograms
に記録されたセッション データの URI が
RecordedPrograms.COLUMN_RECORDING_DATA_URI
列と任意のプログラム
最初の呼び出しでシステムが提供した情報を
onStartRecording()
。
Google Chat の設定にアクセスする方法について詳しくは、
RecordedPrograms
テーブル、
録画セッションの管理セクションをご覧ください。
録画エラーを処理する
録画中にエラーが発生して録画データが使用できない場合は、
システムに通知する場合は
notifyError()
。
また、
録音セッションの作成後にシステムに通知するために notifyError()
アプリがセッションを記録できなくなったことを通知します
録画中にエラーが発生したが、
部分的な録音をユーザーに提供し、再生、通話、
notifyRecordingStopped()
: システムで以下を有効にします。
部分的なセッションを使用します。
録画セッションを管理する
システムは、すべての録画されたセッションの
録画に対応したチャンネル アプリを
RecordedPrograms
コンテンツ プロバイダ テーブル。この情報は
RecordedPrograms
コンテンツ録画の URI などです。Content Provider API を使用して
このテーブルのエントリの読み取り、追加、削除ができます。
コンテンツ プロバイダのデータの操作について詳しくは、
<ph type="x-smartling-placeholder"></ph>
コンテンツ プロバイダの基本をご覧ください。
おすすめの方法
TV デバイスのストレージは限られることがあるため、
録画したセッションを保存するためにストレージを割り当てています。使用
次の場合: RecordingCallback.onError(RECORDING_ERROR_INSUFFICIENT_SPACE)
録画したセッションを保存するのに十分な容量がありません。
ユーザーが録画を開始したら、すぐにデータの記録を開始します。
必要があります。そのためには
時間のかかる作業をすべて行い
たとえば、ストレージ スペースへのアクセスや割り当てなど、
onCreateRecordingSession()
コールバック。これにより
直ちに録音が開始され、
onStartRecording()
コールバックが発生する。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-27 UTC。
[null,null,["最終更新日 2025-07-27 UTC。"],[],[],null,["# Support content recording\n\nTV input services let the user pause and resume channel playback using\n[time-shifting APIs](/training/tv/tif/time-shifting).\nAndroid 7.0 expands on time-shifting\nby letting the user save multiple recorded sessions.\n\nUsers can schedule recordings in advance or start a recording as they watch\na program. Once the system saves a recording, the user can browse, manage,\nand play back the recording using the system TV app.\n\nIf you want to provide recording functionality for your TV input service,\nyou must indicate to the system that your app supports recording, implement\nthe ability to record programs, handle and communicate any errors that occur\nduring recording, and manage your recorded sessions.\n\nIndicate support for recording\n------------------------------\n\nTo tell the system that your TV input service supports recording, set\nthe `android:canRecord` attribute in your service metadata XML file\nto `true`: \n\n```xml\n\u003ctv-input xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:canRecord=\"true\"\n android:setupActivity=\"com.example.sampletvinput.SampleTvInputSetupActivity\" /\u003e\n```\n\nFor more information on the service metadata file, see\n[Declare your TV input\nservice in the manifest](/training/tv/tif/tvinput#manifest).\n\nAlternatively, you can indicate recording support in your code using\nthese steps:\n\n1. In your TV input service [onCreate()](/reference/android/app/Service#onCreate()) method, create a new [TvInputInfo](/reference/android/media/tv/TvInputInfo) object using the [TvInputInfo.Builder](/reference/android/media/tv/TvInputInfo.Builder) class.\n2. When creating the new `TvInputInfo` object, call [setCanRecord(true)](/reference/android/media/tv/TvInputInfo.Builder#setCanRecord(boolean)) before calling [build()](/reference/android/media/tv/TvInputInfo.Builder#build()) to indicate that your service supports recording.\n3. Register your `TvInputInfo` object with the system by calling [TvInputManager.updateTvInputInfo()](/reference/android/media/tv/TvInputManager#updateTvInputInfo(android.media.tv.TvInputInfo)).\n\nRecord a session\n----------------\n\nAfter your TV input service registers that it supports recording\nfunctionality, the system calls your\n[TvInputService.onCreateRecordingSession()](/reference/android/media/tv/TvInputService#onCreateRecordingSession(java.lang.String)) method when it needs to access\nyour app's recording implementation. Implement your own\n[TvInputService.RecordingSession](/reference/android/media/tv/TvInputService.RecordingSession) subclass and return it\nwhen the `onCreateRecordingSession()` callback fires. This subclass is responsible\nfor switching to the correct channel data, recording the requested data,\nand communicating recording status and errors to the system.\n\nWhen the system calls\n[RecordingSession.onTune()](/reference/android/media/tv/TvInputService.RecordingSession#onTune(android.net.Uri)), passing in a channel URI, tune to the channel\nthat the URI specifies. Notify the system that your app has tuned to the\ndesired channel by calling\n[notifyTuned()](/reference/android/media/tv/TvInputService.RecordingSession#notifyTuned(android.net.Uri)) or, if your app can't tune to the proper channel, call\n[notifyError()](/reference/android/media/tv/TvInputService.RecordingSession#notifyError(int)).\n\nThe system next invokes the\n[RecordingSession.onStartRecording()](/reference/android/media/tv/TvInputService.RecordingSession#onStartRecording(android.net.Uri)) callback. Your app must start recording\nimmediately. When the system invokes this callback, it might provide a URI\nthat contains information about the program that is about to be recorded.\nWhen the recording is done, copy this data to the\n[RecordedPrograms](/reference/android/media/tv/TvContract.RecordedPrograms)\ndata table.\n\nFinally, the system calls\n[RecordingSession.onStopRecording()](/reference/android/media/tv/TvInputService.RecordingSession#onStopRecording()). At this point, your app must stop\nrecording immediately. You also need to create an entry in the\n`RecordedPrograms`\ntable that includes the recorded session data URI in the\n[RecordedPrograms.COLUMN_RECORDING_DATA_URI](/reference/android/media/tv/TvContract.RecordedPrograms#COLUMN_RECORDING_DATA_URI) column, and any program\ninformation that the system provided in the initial call to\n`onStartRecording()`.\n\nFor more details on how to access the\n`RecordedPrograms` table,\nsee the [Manage recorded sessions](#sessions) section.\n\nHandle recording errors\n-----------------------\n\nIf an error occurs during recording, resulting in unusable recorded data,\nnotify the system by calling\n[notifyError()](/reference/android/media/tv/TvInputService.RecordingSession#notifyError(int)).\nYou can also call\nnotifyError() after a recording session is created to let the system know\nthat your app can no longer record sessions.\n\nIf an error occurs during recording but you want to provide a\npartial recording to users for playback, call\n[notifyRecordingStopped()](/reference/android/media/tv/TvInputService.RecordingSession#notifyRecordingStopped(android.net.Uri)) to enable the system to\nuse the partial session.\n\nManage recorded sessions\n------------------------\n\nThe system maintains information for all recorded sessions from all\nrecording-capable channel apps in the\n[RecordedPrograms](/reference/android/media/tv/TvContract.RecordedPrograms)\ncontent provider table. This information is accessible through the\nRecordedPrograms\ncontent recording URIs. Use content provider APIs to\nread, add, and delete entries from this table.\n\nFor more information on working with content provider data, see\n[Content provider basics](/guide/topics/providers/content-provider-basics).\n\nBest practices\n--------------\n\nTV devices might have limited storage, so use your best judgment when\nallocating storage to save recorded sessions. Use\n[RecordingCallback.onError(RECORDING_ERROR_INSUFFICIENT_SPACE)](/reference/android/media/tv/TvRecordingClient.RecordingCallback#onError(int)) when\nthere isn't enough space to save a recorded session.\n\nWhen the user initiates recording, start recording data as soon\nas possible. To facilitate this, complete any up-front time-consuming tasks,\nlike accessing and allocating storage space, when the system invokes the\n[onCreateRecordingSession()](/reference/android/media/tv/TvInputService#onCreateRecordingSession(java.lang.String)) callback. Doing so lets you start\nrecording immediately when the\n[onStartRecording()](/reference/android/media/tv/TvInputService.RecordingSession#onStartRecording(android.net.Uri)) callback fires."]]