1*30877f79SAndroid Build Coastguard Worker---
2*30877f79SAndroid Build Coastguard Workertitle: Debug logging
3*30877f79SAndroid Build Coastguard Worker---
4*30877f79SAndroid Build Coastguard Worker
5*30877f79SAndroid Build Coastguard WorkerBy default ExoPlayer only logs errors. To log player events, the `EventLogger`
6*30877f79SAndroid Build Coastguard Workerclass can be used. The additional logging it provides can be helpful for
7*30877f79SAndroid Build Coastguard Workerunderstanding what the player is doing, as well as for debugging playback
8*30877f79SAndroid Build Coastguard Workerissues. `EventLogger` implements `AnalyticsListener`, so registering an instance
9*30877f79SAndroid Build Coastguard Workerwith an `ExoPlayer` is easy:
10*30877f79SAndroid Build Coastguard Worker
11*30877f79SAndroid Build Coastguard Worker```
12*30877f79SAndroid Build Coastguard Workerplayer.addAnalyticsListener(new EventLogger(trackSelector));
13*30877f79SAndroid Build Coastguard Worker```
14*30877f79SAndroid Build Coastguard Worker{: .language-java}
15*30877f79SAndroid Build Coastguard Worker
16*30877f79SAndroid Build Coastguard WorkerPassing the `trackSelector` enables additional logging, but is optional and so
17*30877f79SAndroid Build Coastguard Worker`null` can be passed instead.
18*30877f79SAndroid Build Coastguard Worker
19*30877f79SAndroid Build Coastguard WorkerThe easiest way to observe the log is using Android Studio's [logcat tab][]. You
20*30877f79SAndroid Build Coastguard Workercan select your app as debuggable process by the package name (
21*30877f79SAndroid Build Coastguard Worker`com.google.android.exoplayer2.demo` if using the demo app) and tell the logcat
22*30877f79SAndroid Build Coastguard Workertab to log only for that app by selecting 'show only selected application'. It's
23*30877f79SAndroid Build Coastguard Workerpossible to further filter the logging with the expression
24*30877f79SAndroid Build Coastguard Worker`EventLogger|ExoPlayerImpl`, to get only logging from `EventLogger` and the
25*30877f79SAndroid Build Coastguard Workerplayer itself.
26*30877f79SAndroid Build Coastguard Worker
27*30877f79SAndroid Build Coastguard WorkerAn alternative to using Android Studio's logcat tab is to use the console. For
28*30877f79SAndroid Build Coastguard Workerexample:
29*30877f79SAndroid Build Coastguard Worker
30*30877f79SAndroid Build Coastguard Worker~~~
31*30877f79SAndroid Build Coastguard Workeradb logcat EventLogger:* ExoPlayerImpl:* *:s
32*30877f79SAndroid Build Coastguard Worker~~~
33*30877f79SAndroid Build Coastguard Worker{: .language-shell}
34*30877f79SAndroid Build Coastguard Worker
35*30877f79SAndroid Build Coastguard Worker### Player information ###
36*30877f79SAndroid Build Coastguard Worker
37*30877f79SAndroid Build Coastguard WorkerThe `ExoPlayerImpl` class delivers two important lines about the player version,
38*30877f79SAndroid Build Coastguard Workerthe device and OS the app is running on and the modules of ExoPlayer that have
39*30877f79SAndroid Build Coastguard Workerbeen loaded:
40*30877f79SAndroid Build Coastguard Worker
41*30877f79SAndroid Build Coastguard Worker```
42*30877f79SAndroid Build Coastguard WorkerExoPlayerImpl: Release 2cd6e65 [ExoPlayerLib/2.12.0] [marlin, Pixel XL, Google, 26] [goog.exo.core, goog.exo.ui, goog.exo.dash]
43*30877f79SAndroid Build Coastguard WorkerExoPlayerImpl: Init 2e5194c [ExoPlayerLib/2.12.0] [marlin, Pixel XL, Google, 26]
44*30877f79SAndroid Build Coastguard Worker```
45*30877f79SAndroid Build Coastguard Worker
46*30877f79SAndroid Build Coastguard Worker### Playback state ###
47*30877f79SAndroid Build Coastguard Worker
48*30877f79SAndroid Build Coastguard WorkerPlayer state changes are logged in lines like the ones below:
49*30877f79SAndroid Build Coastguard Worker
50*30877f79SAndroid Build Coastguard Worker```
51*30877f79SAndroid Build Coastguard WorkerEventLogger: playWhenReady [eventTime=0.00, mediaPos=0.00, window=0, true, USER_REQUEST]
52*30877f79SAndroid Build Coastguard WorkerEventLogger: state [eventTime=0.01, mediaPos=0.00, window=0, BUFFERING]
53*30877f79SAndroid Build Coastguard WorkerEventLogger: state [eventTime=0.93, mediaPos=0.00, window=0, period=0, READY]
54*30877f79SAndroid Build Coastguard WorkerEventLogger: isPlaying [eventTime=0.93, mediaPos=0.00, window=0, period=0, true]
55*30877f79SAndroid Build Coastguard WorkerEventLogger: playWhenReady [eventTime=9.40, mediaPos=8.40, window=0, period=0, false, USER_REQUEST]
56*30877f79SAndroid Build Coastguard WorkerEventLogger: isPlaying [eventTime=9.40, mediaPos=8.40, window=0, period=0, false]
57*30877f79SAndroid Build Coastguard WorkerEventLogger: playWhenReady [eventTime=10.40, mediaPos=8.40, window=0, period=0, true, USER_REQUEST]
58*30877f79SAndroid Build Coastguard WorkerEventLogger: isPlaying [eventTime=10.40, mediaPos=8.40, window=0, period=0, true]
59*30877f79SAndroid Build Coastguard WorkerEventLogger: state [eventTime=20.40, mediaPos=18.40, window=0, period=0, ENDED]
60*30877f79SAndroid Build Coastguard WorkerEventLogger: isPlaying [eventTime=20.40, mediaPos=18.40, window=0, period=0, false]
61*30877f79SAndroid Build Coastguard Worker```
62*30877f79SAndroid Build Coastguard Worker
63*30877f79SAndroid Build Coastguard WorkerIn this example playback starts 0.93 seconds after the player is prepared. The
64*30877f79SAndroid Build Coastguard Workeruser pauses playback after 9.4 seconds, and resumes playback one second later at
65*30877f79SAndroid Build Coastguard Worker10.4 seconds. Playback ends ten seconds later at 20.4 seconds. The common
66*30877f79SAndroid Build Coastguard Workerelements within the square brackets are:
67*30877f79SAndroid Build Coastguard Worker
68*30877f79SAndroid Build Coastguard Worker* `[eventTime=float]`: The wall clock time since player creation.
69*30877f79SAndroid Build Coastguard Worker* `[mediaPos=float]`: The current playback position.
70*30877f79SAndroid Build Coastguard Worker* `[window=int]`: The current window index.
71*30877f79SAndroid Build Coastguard Worker* `[period=int]`: The current period in that window.
72*30877f79SAndroid Build Coastguard Worker
73*30877f79SAndroid Build Coastguard WorkerThe final elements in each line indicate the value of the state being reported.
74*30877f79SAndroid Build Coastguard Worker
75*30877f79SAndroid Build Coastguard Worker### Media tracks ###
76*30877f79SAndroid Build Coastguard Worker
77*30877f79SAndroid Build Coastguard WorkerTrack information is logged when the available or selected tracks change. This
78*30877f79SAndroid Build Coastguard Workerhappens at least once at the start of playback. The example below shows track
79*30877f79SAndroid Build Coastguard Workerlogging for an adaptive stream:
80*30877f79SAndroid Build Coastguard Worker
81*30877f79SAndroid Build Coastguard Worker```
82*30877f79SAndroid Build Coastguard WorkerEventLogger: tracks [eventTime=0.30, mediaPos=0.00, window=0, period=0,
83*30877f79SAndroid Build Coastguard WorkerEventLogger:   MediaCodecVideoRenderer [
84*30877f79SAndroid Build Coastguard WorkerEventLogger:     Group:0, adaptive_supported=YES [
85*30877f79SAndroid Build Coastguard WorkerEventLogger:       [X] Track:0, id=133, mimeType=video/avc, bitrate=261112, codecs=avc1.4d4015, res=426x240, fps=30.0, supported=YES
86*30877f79SAndroid Build Coastguard WorkerEventLogger:       [X] Track:1, id=134, mimeType=video/avc, bitrate=671331, codecs=avc1.4d401e, res=640x360, fps=30.0, supported=YES
87*30877f79SAndroid Build Coastguard WorkerEventLogger:       [X] Track:2, id=135, mimeType=video/avc, bitrate=1204535, codecs=avc1.4d401f, res=854x480, fps=30.0, supported=YES
88*30877f79SAndroid Build Coastguard WorkerEventLogger:       [X] Track:3, id=160, mimeType=video/avc, bitrate=112329, codecs=avc1.4d400c, res=256x144, fps=30.0, supported=YES
89*30877f79SAndroid Build Coastguard WorkerEventLogger:       [ ] Track:4, id=136, mimeType=video/avc, bitrate=2400538, codecs=avc1.4d401f, res=1280x720, fps=30.0, supported=NO_EXCEEDS_CAPABILITIES
90*30877f79SAndroid Build Coastguard WorkerEventLogger:     ]
91*30877f79SAndroid Build Coastguard WorkerEventLogger:   ]
92*30877f79SAndroid Build Coastguard WorkerEventLogger:   MediaCodecAudioRenderer [
93*30877f79SAndroid Build Coastguard WorkerEventLogger:     Group:0, adaptive_supported=YES_NOT_SEAMLESS [
94*30877f79SAndroid Build Coastguard WorkerEventLogger:       [ ] Track:0, id=139, mimeType=audio/mp4a-latm, bitrate=48582, codecs=mp4a.40.5, channels=2, sample_rate=22050, supported=YES
95*30877f79SAndroid Build Coastguard WorkerEventLogger:       [X] Track:1, id=140, mimeType=audio/mp4a-latm, bitrate=127868, codecs=mp4a.40.2, channels=2, sample_rate=44100, supported=YES
96*30877f79SAndroid Build Coastguard WorkerEventLogger:     ]
97*30877f79SAndroid Build Coastguard WorkerEventLogger:   ]
98*30877f79SAndroid Build Coastguard WorkerEventLogger: ]
99*30877f79SAndroid Build Coastguard Worker```
100*30877f79SAndroid Build Coastguard Worker
101*30877f79SAndroid Build Coastguard WorkerIn this example, the player has selected four of the five available video
102*30877f79SAndroid Build Coastguard Workertracks. The fifth video track is not selected because it exceeds the
103*30877f79SAndroid Build Coastguard Workercapabilities of the device, as indicated by `supported=NO_EXCEEDS_CAPABILITIES`.
104*30877f79SAndroid Build Coastguard WorkerThe player will adapt between the selected video tracks during playback. When
105*30877f79SAndroid Build Coastguard Workerthe player adapts from one track to another, it's logged in a line like the one
106*30877f79SAndroid Build Coastguard Workerbelow:
107*30877f79SAndroid Build Coastguard Worker
108*30877f79SAndroid Build Coastguard Worker```
109*30877f79SAndroid Build Coastguard WorkerEventLogger: downstreamFormat [eventTime=3.64, mediaPos=3.00, window=0, period=0, id=134, mimeType=video/avc, bitrate=671331, codecs=avc1.4d401e, res=640x360, fps=30.0]
110*30877f79SAndroid Build Coastguard Worker```
111*30877f79SAndroid Build Coastguard Worker
112*30877f79SAndroid Build Coastguard WorkerThis log line indicates that the player switched to the 640x360 resolution video
113*30877f79SAndroid Build Coastguard Workertrack three seconds into the media.
114*30877f79SAndroid Build Coastguard Worker
115*30877f79SAndroid Build Coastguard Worker### Decoder selection ###
116*30877f79SAndroid Build Coastguard Worker
117*30877f79SAndroid Build Coastguard WorkerIn most cases ExoPlayer renders media using a `MediaCodec` acquired from the
118*30877f79SAndroid Build Coastguard Workerunderlying platform. When a decoder is initialized, this is logged in lines like
119*30877f79SAndroid Build Coastguard Workerthe ones below:
120*30877f79SAndroid Build Coastguard Worker
121*30877f79SAndroid Build Coastguard Worker```
122*30877f79SAndroid Build Coastguard WorkerEventLogger: videoDecoderInitialized [0.77, 0.00, window=0, period=0, video, OMX.qcom.video.decoder.avc]
123*30877f79SAndroid Build Coastguard WorkerEventLogger: audioDecoderInitialized [0.79, 0.00, window=0, period=0, audio, OMX.google.aac.decoder]
124*30877f79SAndroid Build Coastguard Worker```
125*30877f79SAndroid Build Coastguard Worker
126*30877f79SAndroid Build Coastguard Worker[logcat tab]: https://developer.android.com/studio/debug/am-logcat
127