diff --git a/docs/html/_redirects.yaml b/docs/html/_redirects.yaml index 837b222ffb2b1..b6d28dc1d4c92 100644 --- a/docs/html/_redirects.yaml +++ b/docs/html/_redirects.yaml @@ -1210,3 +1210,5 @@ redirects: to: /training/articles/security-config.html - from: /preview/features/picture-in-picture.html to: /training/tv/playback/picture-in-picture.html +- from: /preview/features/tv-recording-api.html + to: /training/tv/tif/content-recording.html diff --git a/docs/html/preview/features/tv-recording-api.jd b/docs/html/preview/features/tv-recording-api.jd deleted file mode 100644 index 6619821d7fe9f..0000000000000 --- a/docs/html/preview/features/tv-recording-api.jd +++ /dev/null @@ -1,142 +0,0 @@ -page.title=TV Recording -page.keywords=preview,sdk,tv,recording -page.tags=androidn -page.image=images/cards/card-nyc_2x.jpg - -@jd:body - -
-
-

In this document

-
    -
  1. Indicating Support for Recording
  2. -
  3. Recording a Session
  4. -
  5. Handling Recording Errors
  6. -
  7. Managing Recorded Sessions
  8. -
  9. Best Practices
  10. -
-
-
- -

TV input services let the user pause and resume channel playback via -time-shifting APIs. Android N expands on time-shifting -by letting the user save multiple recorded sessions.

- -

Users can schedule recordings in advance, or start a recording as they watch -a program. Once the system has saved a recording, the user can browse, manage, -and play back the recording using the system TV app.

- -

If you want to provide recording functionality for your TV input service, -you must indicate to the system that your app supports recording, implement -the ability to record programs, handle and communicate any errors that occur -during recording, and manage your recorded sessions.

- -

Note: The Live Channels app does not yet -provide a way for users to create or access recordings. Until changes are -made to the Live Channels app, it may be difficult to fully test the recording -experience for your TV input service.

- -

Indicating Support for Recording

- -

To tell the system that your TV input service supports recording, set -the android:canRecord attribute in your service metadata XML file -to true: -

- -
-<tv-input xmlns:android="http://schemas.android.com/apk/res/android"
-  android:canRecord="true"
-  android:setupActivity="com.example.sampletvinput.SampleTvInputSetupActivity" />
-
- -

For more information on the service metadata file, see -Declare Your TV Input -Service in the Manifest. -

- -

Alternatively, you can indicate recording support in your code using -these steps:

- -
    -
  1. In your TvInputService.onCreate() method, create a new -TvInputInfo object using the TvInputInfo.Builder -class.
  2. -
  3. When creating the new TvInputInfo object, call -setCanRecord(true) before calling build() to -indicate your service supports recording.
  4. -
  5. Register your TvInputInfo object with the system by calling -TvInputManager.updateTvInputInfo().
  6. -
- -

Recording a Session

- -

After your TV input service registers that it supports recording -functionality, the system calls your -TvInputService.onCreateRecordingSession() when it needs to access -your app's recording implementation. Implement your own -TvInputService.RecordingSession subclass and return it -when the onCreateRecordingSession() callback -fires. This subclass is responsible for switching to the correct channel data, -recording the requested data, and communicating recording status and errors to -the system.

- -

When the system calls RecordingSession.onTune(), passing in a -channel URI, tune to the channel that the URI specifies. Notify the system that -your app has tuned to the desired channel by calling notifyTuned(), -or, if your app could not tune to the proper channel, call -notifyError().

- -

The system next invokes the RecordingSession.onStartRecording() -callback. Your app must start recording immediately. When the system invokes -this callback, it may provide a URI that contains information about the program -that is about to be recorded. When the recording is done, you need to copy this -data to the RecordedPrograms data table.

- -

Finally, the system calls RecordingSession.onStopRecording(). -At this point, your app must stop recording immediately. You also need to -create an entry in the RecordedPrograms table. This entry should -include the recorded session data URI in the -RecordedPrograms.COLUMN_RECORDING_DATA_URI column, and any program -information that the system provided in the initial call to -onStartRecording().

- -

For more details on how to access the RecordedPrograms table -see Managing Recorded Sessions.

- -

Handling Recording Errors

- -

If an error occurs during recording, rendering the recorded data unusable, -notify the system by calling RecordingSession.notifyError(). -Similarly, you can call notifyError() after a recording session is -created to let the system know that your app can no longer record sessions.

- -

If an error occurs during recording, but you'd like to provide a usable -partial recording to users for playback, call -RecordingSession.notifyRecordingStopped() to enable the system to -use the partial session.

- -

Managing Recorded Sessions

- -

The system maintains information for all recorded sessions from all -recording-capable channel apps in the TvContract.RecordedPrograms -content provider table. This information is accessible via the -RecordedPrograms.Uri content URI. Use content provider APIs to -read, add, and delete entries from this table.

- -

For more information on working with content provider data see - -Content Provider Basics .

- -

Best Practices

- -

TV devices may have limited storage, so use your best judgment when -allocating storage to save recorded sessions. Use -RecordingCallback.onError(RECORDING_ERROR_INSUFFICIENT_SPACE) when -there isn't enough space to save a recorded session.

- -

When the user initiates recording, you should start recording data as soon -as possible. To facilitate this, complete any up-front time-consuming tasks, -like accessing and allocating storage space, when the system invokes the -onCreateRecordingSession() callback. Doing so lets you start -recording immediately when the onStartRecording() callback -fires.

diff --git a/docs/html/training/_book.yaml b/docs/html/training/_book.yaml index 6142dba6cb7d8..0054c5cfe33a2 100644 --- a/docs/html/training/_book.yaml +++ b/docs/html/training/_book.yaml @@ -726,6 +726,8 @@ toc: path: /training/tv/tif/channel.html - title: Managing User Interaction path: /training/tv/tif/ui.html + - title: Supporting Content Recording + path: /training/tv/tif/content-recording.html - title: TV Apps Checklist path: /training/tv/publishing/checklist.html path_attributes: diff --git a/docs/html/training/tv/tif/content-recording.jd b/docs/html/training/tv/tif/content-recording.jd new file mode 100644 index 0000000000000..ffdd14cb64398 --- /dev/null +++ b/docs/html/training/tv/tif/content-recording.jd @@ -0,0 +1,171 @@ +page.title=Supporting Content Recording +page.keywords=tv,recording,channel,tif +page.tags=tv, tif +helpoutsWidget=true + +trainingnavtop=true + +@jd:body + +
+
+

In this document

+
    +
  1. Indicating Support for Recording
  2. +
  3. Recording a Session
  4. +
  5. Handling Recording Errors
  6. +
  7. Managing Recorded Sessions
  8. +
  9. Best Practices
  10. +
+
+
+ +

TV input services let the user pause and resume channel playback via +time-shifting APIs. Android 7.0 expands on time-shifting +by letting the user save multiple recorded sessions.

+ +

Users can schedule recordings in advance, or start a recording as they watch +a program. Once the system has saved a recording, the user can browse, manage, +and play back the recording using the system TV app.

+ +

If you want to provide recording functionality for your TV input service, +you must indicate to the system that your app supports recording, implement +the ability to record programs, handle and communicate any errors that occur +during recording, and manage your recorded sessions.

+ +

Note: The Live Channels app does not yet +provide a way for users to create or access recordings. Until changes are +made to the Live Channels app, it may be difficult to fully test the recording +experience for your TV input service.

+ +

Indicating Support for Recording

+ +

To tell the system that your TV input service supports recording, set +the android:canRecord attribute in your service metadata XML file +to true: +

+ +
+<tv-input xmlns:android="http://schemas.android.com/apk/res/android"
+  android:canRecord="true"
+  android:setupActivity="com.example.sampletvinput.SampleTvInputSetupActivity" />
+
+ +

For more information on the service metadata file, see +Declare Your TV Input +Service in the Manifest. +

+ +

Alternatively, you can indicate recording support in your code using +these steps:

+ +
    +
  1. In your TV input service {@link android.app.Service#onCreate onCreate()} +method, create a new {@link android.media.tv.TvInputInfo} object using the +{@link android.media.tv.TvInputInfo.Builder TvInputInfo.Builder} class.
  2. +
  3. When creating the new {@link android.media.tv.TvInputInfo} object, call +{@link android.media.tv.TvInputInfo.Builder#setCanRecord +setCanRecord(true)} before calling +{@link android.media.tv.TvInputInfo.Builder#build build()} to indicate your +service supports recording.
  4. +
  5. Register your {@link android.media.tv.TvInputInfo} object with the +system by calling +{@link android.media.tv.TvInputManager#updateTvInputInfo +TvInputManager.updateTvInputInfo()}.
  6. +
+ +

Recording a Session

+ +

After your TV input service registers that it supports recording +functionality, the system calls your +{@link android.media.tv.TvInputService#onCreateRecordingSession +TvInputService.onCreateRecordingSession()} method when it needs to access +your app's recording implementation. Implement your own +{@link android.media.tv.TvInputService.RecordingSession +TvInputService.RecordingSession} subclass and return it +when the {@link android.media.tv.TvInputService#onCreateRecordingSession +onCreateRecordingSession()} callback fires. This subclass is responsible +for switching to the correct channel data, recording the requested data, +and communicating recording status and errors to the system.

+ +

When the system calls +{@link android.media.tv.TvInputService.RecordingSession#onTune +RecordingSession.onTune()}, passing in a channel URI, tune to the channel +that the URI specifies. Notify the system that your app has tuned to the +desired channel by calling +{@link android.media.tv.TvInputService.RecordingSession#notifyTuned +notifyTuned()} or, if your app could not tune to the proper channel, call +{@link android.media.tv.TvInputService.RecordingSession#notifyError +notifyError()}.

+ +

The system next invokes the +{@link android.media.tv.TvInputService.RecordingSession#onStartRecording +RecordingSession.onStartRecording()} callback. Your app must start recording +immediately. When the system invokes this callback, it may provide a URI +that contains information about the program that is about to be recorded. +When the recording is done, you'll copy this data to the +{@link android.media.tv.TvContract.RecordedPrograms RecordedPrograms} +data table.

+ +

Finally, the system calls +{@link android.media.tv.TvInputService.RecordingSession#onStopRecording +RecordingSession.onStopRecording()}. At this point, your app must stop +recording immediately. You also need to create an entry in the +{@link android.media.tv.TvContract.RecordedPrograms RecordedPrograms} +table. This entry should include the recorded session data URI in the +{@link android.media.tv.TvContract.RecordedPrograms#COLUMN_RECORDING_DATA_URI +RecordedPrograms.COLUMN_RECORDING_DATA_URI} column, and any program +information that the system provided in the initial call to +{@link android.media.tv.TvInputService.RecordingSession#onStartRecording +onStartRecording()}.

+ +

For more details on how to access the +{@link android.media.tv.TvContract.RecordedPrograms RecordedPrograms} table +see Managing Recorded Sessions.

+ +

Handling Recording Errors

+ +

If an error occurs during recording, resulting in unusable recorded data, +notify the system by calling +{@link android.media.tv.TvInputService.RecordingSession#notifyError +notifyError()}. Similarly, you can call +{@link android.media.tv.TvInputService.RecordingSession#notifyError +notifyError()} after a recording session is created to let the system know +that your app can no longer record sessions.

+ +

If an error occurs during recording, but you'd like to provide a +partial recording to users for playback, call +{@link android.media.tv.TvInputService.RecordingSession#notifyRecordingStopped +notifyRecordingStopped()} to enable the system to +use the partial session.

+ +

Managing Recorded Sessions

+ +

The system maintains information for all recorded sessions from all +recording-capable channel apps in the +{@link android.media.tv.TvContract.RecordedPrograms RecordedPrograms} +content provider table. This information is accessible via the +{@link android.media.tv.TvContract.RecordedPrograms RecordedPrograms} +content recording URIs. Use content provider APIs to +read, add, and delete entries from this table.

+ +

For more information on working with content provider data see + +Content Provider Basics.

+ +

Best Practices

+ +

TV devices may have limited storage, so use your best judgment when +allocating storage to save recorded sessions. Use +{@link android.media.tv.TvRecordingClient.RecordingCallback#onError +RecordingCallback.onError(RECORDING_ERROR_INSUFFICIENT_SPACE)} when +there isn't enough space to save a recorded session.

+ +

When the user initiates recording, you should start recording data as soon +as possible. To facilitate this, complete any up-front time-consuming tasks, +like accessing and allocating storage space, when the system invokes the +{@link android.media.tv.TvInputService#onCreateRecordingSession +onCreateRecordingSession()} callback. Doing so lets you start +recording immediately when the +{@link android.media.tv.TvInputService.RecordingSession#onStartRecording +onStartRecording()} callback fires.