|
8 | 8 | import android.widget.Button; |
9 | 9 | import android.widget.Toast; |
10 | 10 |
|
| 11 | +import androidx.annotation.NonNull; |
11 | 12 | import androidx.appcompat.app.AppCompatActivity; |
12 | 13 | import androidx.core.content.ContextCompat; |
13 | 14 |
|
14 | | -import com.google.android.exoplayer2.ExoPlayerFactory; |
15 | | -import com.google.android.exoplayer2.SimpleExoPlayer; |
16 | | -import com.google.android.exoplayer2.source.ExtractorMediaSource; |
| 15 | +import com.google.android.exoplayer2.ExoPlayer; |
| 16 | +import com.google.android.exoplayer2.MediaItem; |
| 17 | +import com.google.android.exoplayer2.Player; |
17 | 18 | import com.google.android.exoplayer2.source.MediaSource; |
| 19 | +import com.google.android.exoplayer2.source.ProgressiveMediaSource; |
18 | 20 | import com.google.android.exoplayer2.ui.PlayerControlView; |
19 | 21 | import com.google.android.exoplayer2.upstream.DataSource; |
20 | | -import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; |
21 | | -import com.google.android.exoplayer2.util.Util; |
22 | | -import com.google.android.exoplayer2.video.VideoListener; |
| 22 | +import com.google.android.exoplayer2.upstream.DefaultDataSource; |
| 23 | +import com.google.android.exoplayer2.video.VideoSize; |
23 | 24 | import com.otaliastudios.zoom.ZoomImageView; |
24 | 25 | import com.otaliastudios.zoom.ZoomLayout; |
25 | 26 | import com.otaliastudios.zoom.ZoomLogger; |
26 | 27 | import com.otaliastudios.zoom.ZoomSurfaceView; |
27 | 28 |
|
28 | | -import org.jetbrains.annotations.NotNull; |
29 | | - |
30 | | - |
31 | 29 | public class MainActivity extends AppCompatActivity { |
32 | 30 |
|
33 | | - private SimpleExoPlayer player; |
| 31 | + private ExoPlayer player; |
34 | 32 |
|
35 | 33 | @Override |
36 | 34 | protected void onCreate(Bundle savedInstanceState) { |
@@ -111,34 +109,34 @@ protected void onStart() { |
111 | 109 |
|
112 | 110 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) |
113 | 111 | private void setUpVideoPlayer() { |
114 | | - player = ExoPlayerFactory.newSimpleInstance(this); |
| 112 | + player = new ExoPlayer.Builder(this).build(); |
115 | 113 | PlayerControlView controls = findViewById(R.id.player_control_view); |
116 | 114 | final ZoomSurfaceView surface = findViewById(R.id.surface_view); |
117 | | - player.addVideoListener(new VideoListener() { |
| 115 | + player.addListener(new Player.Listener() { |
118 | 116 | @Override |
119 | | - public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) { |
120 | | - surface.setContentSize(width, height); |
| 117 | + public void onVideoSizeChanged(@NonNull VideoSize videoSize) { |
| 118 | + surface.setContentSize(videoSize.width, videoSize.height); |
121 | 119 | } |
122 | 120 | }); |
123 | 121 | surface.setBackgroundColor(ContextCompat.getColor(this, R.color.background)); |
124 | 122 | surface.addCallback(new ZoomSurfaceView.Callback() { |
125 | 123 | @Override |
126 | | - public void onZoomSurfaceCreated(@NotNull ZoomSurfaceView view) { |
| 124 | + public void onZoomSurfaceCreated(@NonNull ZoomSurfaceView view) { |
127 | 125 | player.setVideoSurface(view.getSurface()); |
128 | 126 | } |
129 | 127 |
|
130 | 128 | @Override |
131 | | - public void onZoomSurfaceDestroyed(@NotNull ZoomSurfaceView view) { } |
| 129 | + public void onZoomSurfaceDestroyed(@NonNull ZoomSurfaceView view) { } |
132 | 130 | }); |
133 | 131 | controls.setPlayer(player); |
134 | 132 | controls.setShowTimeoutMs(0); |
135 | 133 | controls.show(); |
136 | | - DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, |
137 | | - Util.getUserAgent(this, "ZoomLayoutLib")); |
| 134 | + DataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(this); |
138 | 135 | Uri videoUri = Uri.parse("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"); |
139 | | - MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory) |
140 | | - .createMediaSource(videoUri); |
141 | | - player.prepare(videoSource); |
| 136 | + MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory) |
| 137 | + .createMediaSource(MediaItem.fromUri(videoUri)); |
| 138 | + player.setMediaSource(videoSource); |
| 139 | + player.prepare(); |
142 | 140 | } |
143 | 141 |
|
144 | 142 | @Override |
|
0 commit comments