• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.google.android.exoplayer2.upstream;
17 
18 /**
19  * A listener of data transfer events.
20  *
21  * <p>A transfer usually progresses through multiple steps:
22  *
23  * <ol>
24  *   <li>Initializing the underlying resource (e.g. opening a HTTP connection). {@link
25  *       #onTransferInitializing(DataSource, DataSpec, boolean)} is called before the initialization
26  *       starts.
27  *   <li>Starting the transfer after successfully initializing the resource. {@link
28  *       #onTransferStart(DataSource, DataSpec, boolean)} is called. Note that this only happens if
29  *       the initialization was successful.
30  *   <li>Transferring data. {@link #onBytesTransferred(DataSource, DataSpec, boolean, int)} is
31  *       called frequently during the transfer to indicate progress.
32  *   <li>Closing the transfer and the underlying resource. {@link #onTransferEnd(DataSource,
33  *       DataSpec, boolean)} is called. Note that each {@link #onTransferStart(DataSource, DataSpec,
34  *       boolean)} will have exactly one corresponding call to {@link #onTransferEnd(DataSource,
35  *       DataSpec, boolean)}.
36  * </ol>
37  */
38 public interface TransferListener {
39 
40   /**
41    * Called when a transfer is being initialized.
42    *
43    * @param source The source performing the transfer.
44    * @param dataSpec Describes the data for which the transfer is initialized.
45    * @param isNetwork Whether the data is transferred through a network.
46    */
onTransferInitializing(DataSource source, DataSpec dataSpec, boolean isNetwork)47   void onTransferInitializing(DataSource source, DataSpec dataSpec, boolean isNetwork);
48 
49   /**
50    * Called when a transfer starts.
51    *
52    * @param source The source performing the transfer.
53    * @param dataSpec Describes the data being transferred.
54    * @param isNetwork Whether the data is transferred through a network.
55    */
onTransferStart(DataSource source, DataSpec dataSpec, boolean isNetwork)56   void onTransferStart(DataSource source, DataSpec dataSpec, boolean isNetwork);
57 
58   /**
59    * Called incrementally during a transfer.
60    *
61    * @param source The source performing the transfer.
62    * @param dataSpec Describes the data being transferred.
63    * @param isNetwork Whether the data is transferred through a network.
64    * @param bytesTransferred The number of bytes transferred since the previous call to this method
65    */
onBytesTransferred( DataSource source, DataSpec dataSpec, boolean isNetwork, int bytesTransferred)66   void onBytesTransferred(
67       DataSource source, DataSpec dataSpec, boolean isNetwork, int bytesTransferred);
68 
69   /**
70    * Called when a transfer ends.
71    *
72    * @param source The source performing the transfer.
73    * @param dataSpec Describes the data being transferred.
74    * @param isNetwork Whether the data is transferred through a network.
75    */
onTransferEnd(DataSource source, DataSpec dataSpec, boolean isNetwork)76   void onTransferEnd(DataSource source, DataSpec dataSpec, boolean isNetwork);
77 }
78