15
15
*/
16
16
package androidx .media3 .exoplayer .e2etest ;
17
17
18
+ import static org .robolectric .annotation .GraphicsMode .Mode .NATIVE ;
19
+
18
20
import android .content .Context ;
19
21
import android .graphics .SurfaceTexture ;
20
22
import android .view .Surface ;
23
+ import androidx .annotation .Nullable ;
21
24
import androidx .media3 .common .MediaItem ;
22
25
import androidx .media3 .common .Player ;
23
26
import androidx .media3 .exoplayer .ExoPlayer ;
35
38
import org .robolectric .ParameterizedRobolectricTestRunner ;
36
39
import org .robolectric .ParameterizedRobolectricTestRunner .Parameter ;
37
40
import org .robolectric .ParameterizedRobolectricTestRunner .Parameters ;
41
+ import org .robolectric .annotation .GraphicsMode ;
38
42
39
43
/** End-to-end tests using MP4 samples. */
44
+ @ GraphicsMode (NATIVE )
40
45
@ RunWith (ParameterizedRobolectricTestRunner .class )
41
46
public class Mp4PlaybackTest {
42
47
43
48
@ Parameters (name = "{0}" )
44
- public static ImmutableList <String > mediaSamples () {
49
+ public static ImmutableList <Sample > mediaSamples () {
45
50
return ImmutableList .of (
46
- "midroll-5s.mp4" ,
47
- "postroll-5s.mp4" ,
48
- "preroll-5s.mp4" ,
49
- "pixel-motion-photo-2-hevc-tracks.mp4" ,
50
- "sample_ac3_fragmented.mp4" ,
51
- "sample_ac3.mp4" ,
52
- "sample_ac4_fragmented.mp4" ,
53
- "sample_ac4.mp4" ,
54
- "sample_android_slow_motion.mp4" ,
55
- "sample_eac3_fragmented.mp4" ,
56
- "sample_eac3.mp4" ,
57
- "sample_eac3joc_fragmented.mp4" ,
58
- "sample_eac3joc.mp4" ,
59
- "sample_fragmented.mp4" ,
60
- "sample_fragmented_seekable.mp4" ,
61
- "sample_fragmented_large_bitrates.mp4" ,
62
- "sample_fragmented_sei.mp4" ,
63
- "sample_mdat_too_long.mp4" ,
64
- "sample.mp4" ,
65
- "sample_with_metadata.mp4" ,
66
- "sample_with_numeric_genre.mp4" ,
67
- "sample_opus_fragmented.mp4" ,
68
- "sample_opus.mp4" ,
69
- "sample_partially_fragmented.mp4" ,
70
- "testvid_1022ms.mp4" ,
71
- "sample_edit_list.mp4" ,
72
- "sample_edit_list_no_sync_frame_before_edit.mp4" );
51
+ Sample .forFile ("midroll-5s.mp4" ),
52
+ Sample .forFile ("postroll-5s.mp4" ),
53
+ Sample .forFile ("preroll-5s.mp4" ),
54
+ Sample .forFile ("pixel-motion-photo-2-hevc-tracks.mp4" ),
55
+ Sample .forFile ("sample_ac3_fragmented.mp4" ),
56
+ Sample .forFile ("sample_ac3.mp4" ),
57
+ Sample .forFile ("sample_ac4_fragmented.mp4" ),
58
+ Sample .forFile ("sample_ac4.mp4" ),
59
+ Sample .forFile ("sample_android_slow_motion.mp4" ),
60
+ Sample .forFile ("sample_eac3_fragmented.mp4" ),
61
+ Sample .forFile ("sample_eac3.mp4" ),
62
+ Sample .forFile ("sample_eac3joc_fragmented.mp4" ),
63
+ Sample .forFile ("sample_eac3joc.mp4" ),
64
+ Sample .forFile ("sample_fragmented.mp4" ),
65
+ Sample .forFile ("sample_fragmented_seekable.mp4" ),
66
+ Sample .forFile ("sample_fragmented_large_bitrates.mp4" ),
67
+ Sample .forFile ("sample_fragmented_sei.mp4" ),
68
+ Sample .forFile ("sample_mdat_too_long.mp4" ),
69
+ Sample .forFile ("sample.mp4" ),
70
+ Sample .forFile ("sample_with_metadata.mp4" ),
71
+ Sample .forFile ("sample_with_numeric_genre.mp4" ),
72
+ Sample .forFile ("sample_opus_fragmented.mp4" ),
73
+ Sample .forFile ("sample_opus.mp4" ),
74
+ Sample .forFile ("sample_partially_fragmented.mp4" ),
75
+ Sample .withSubtitles ("sample_with_vobsub.mp4" , "eng" ),
76
+ Sample .forFile ("testvid_1022ms.mp4" ),
77
+ Sample .forFile ("sample_edit_list.mp4" ),
78
+ Sample .forFile ("sample_edit_list_no_sync_frame_before_edit.mp4" ));
73
79
}
74
80
75
- @ Parameter public String inputFile ;
81
+ @ Parameter public Sample sample ;
76
82
77
83
@ Rule
78
84
public ShadowMediaCodecConfig mediaCodecConfig =
@@ -86,19 +92,50 @@ public void test() throws Exception {
86
92
new ExoPlayer .Builder (applicationContext , renderersFactory )
87
93
.setClock (new FakeClock (/* isAutoAdvancing= */ true ))
88
94
.build ();
95
+ if (sample .subtitleLanguageToSelect != null ) {
96
+ player .setTrackSelectionParameters (
97
+ player
98
+ .getTrackSelectionParameters ()
99
+ .buildUpon ()
100
+ .setPreferredTextLanguage (sample .subtitleLanguageToSelect )
101
+ .build ());
102
+ }
89
103
Surface surface = new Surface (new SurfaceTexture (/* texName= */ 1 ));
90
104
player .setVideoSurface (surface );
91
105
92
106
PlaybackOutput playbackOutput = PlaybackOutput .register (player , renderersFactory );
93
107
94
- player .setMediaItem (MediaItem .fromUri ("asset:///media/mp4/" + inputFile ));
108
+ player .setMediaItem (MediaItem .fromUri ("asset:///media/mp4/" + sample . filename ));
95
109
player .prepare ();
96
110
player .play ();
97
111
TestPlayerRunHelper .runUntilPlaybackState (player , Player .STATE_ENDED );
98
112
player .release ();
99
113
surface .release ();
100
114
101
115
DumpFileAsserts .assertOutput (
102
- applicationContext , playbackOutput , "playbackdumps/mp4/" + inputFile + ".dump" );
116
+ applicationContext , playbackOutput , "playbackdumps/mp4/" + sample .filename + ".dump" );
117
+ }
118
+
119
+ private static final class Sample {
120
+ public final String filename ;
121
+ @ Nullable public final String subtitleLanguageToSelect ;
122
+
123
+ private Sample (String filename , @ Nullable String subtitleLanguageToSelect ) {
124
+ this .filename = filename ;
125
+ this .subtitleLanguageToSelect = subtitleLanguageToSelect ;
126
+ }
127
+
128
+ public static Sample forFile (String filename ) {
129
+ return new Sample (filename , /* subtitleLanguageToSelect= */ null );
130
+ }
131
+
132
+ public static Sample withSubtitles (String filename , String subtitleLanguageToSelect ) {
133
+ return new Sample (filename , /* enableSubtitles= */ subtitleLanguageToSelect );
134
+ }
135
+
136
+ @ Override
137
+ public String toString () {
138
+ return filename ;
139
+ }
103
140
}
104
141
}
0 commit comments