-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
211 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
app/src/main/java/cz/zegkljan/videoreferee/ZoomPlayerView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package cz.zegkljan.videoreferee | ||
|
||
import android.content.Context | ||
import android.graphics.Matrix | ||
import android.opengl.GLSurfaceView | ||
import android.util.AttributeSet | ||
import android.util.Log | ||
import android.view.SurfaceView | ||
import android.view.View | ||
import com.google.android.exoplayer2.Player | ||
import com.google.android.exoplayer2.ui.PlayerView | ||
import com.google.android.exoplayer2.video.VideoSize | ||
import com.otaliastudios.zoom.ZoomEngine | ||
import com.otaliastudios.zoom.ZoomSurfaceView | ||
|
||
class ZoomPlayerView(context: Context, attrs: AttributeSet?) : PlayerView(context, attrs) { | ||
private var isZoomedIn: Boolean = false | ||
private val surfaceView: ZoomSurfaceView = findViewById(R.id.player_surface_view) | ||
|
||
init { | ||
val zoomEngineListener = object : ZoomEngine.Listener { | ||
override fun onIdle(engine: ZoomEngine) { | ||
showController() | ||
} | ||
|
||
override fun onUpdate(engine: ZoomEngine, matrix: Matrix) { | ||
hideController() | ||
/* | ||
isZoomedIn = engine.zoom > 1 | ||
val finalResizeMode = if (isZoomedIn) | ||
AspectRatioFrameLayout.RESIZE_MODE_FILL | ||
else | ||
AspectRatioFrameLayout.RESIZE_MODE_FIT | ||
if (finalResizeMode != resizeMode) { | ||
resizeMode = finalResizeMode | ||
} | ||
*/ | ||
} | ||
} | ||
|
||
val playerSurfaceViewListener = object : Player.Listener { | ||
override fun onVideoSizeChanged(videoSize: VideoSize) { | ||
surfaceView.setContentSize(videoSize.width.toFloat(), videoSize.height.toFloat()) | ||
} | ||
} | ||
|
||
surfaceView.addCallback(object : ZoomSurfaceView.Callback { | ||
override fun onZoomSurfaceCreated(view: ZoomSurfaceView) { | ||
view.engine.addListener(zoomEngineListener) | ||
player?.setVideoSurface(view.surface) | ||
player?.addListener(playerSurfaceViewListener) | ||
} | ||
|
||
override fun onZoomSurfaceDestroyed(view: ZoomSurfaceView) { | ||
//view.engine.removeListener(zoomEngineListener) | ||
player?.removeListener(playerSurfaceViewListener) | ||
player?.setVideoSurface(null) | ||
} | ||
}) | ||
} | ||
|
||
override fun setPlayer(player: Player?) { | ||
super.setPlayer(player) | ||
|
||
if (player == null) { | ||
return | ||
} | ||
if (player.isCommandAvailable(Player.COMMAND_SET_VIDEO_SURFACE)) { | ||
if (surfaceView is SurfaceView) { | ||
player.setVideoSurfaceView(surfaceView as SurfaceView) | ||
} | ||
} | ||
if (player.isCommandAvailable(Player.COMMAND_GET_TEXT)) { | ||
subtitleView?.setCues(player.currentCues) | ||
} | ||
} | ||
|
||
override fun setVisibility(visibility: Int) { | ||
super.setVisibility(visibility) | ||
if (surfaceView is SurfaceView) { | ||
// Work around https://github.com/google/ExoPlayer/issues/3160. | ||
surfaceView.visibility = visibility | ||
} | ||
} | ||
|
||
override fun getVideoSurfaceView(): View { | ||
return surfaceView | ||
} | ||
|
||
override fun onResume() { | ||
if (surfaceView is GLSurfaceView) { | ||
(surfaceView as GLSurfaceView).onResume() | ||
} | ||
} | ||
|
||
override fun onPause() { | ||
if (surfaceView is GLSurfaceView) { | ||
(surfaceView as GLSurfaceView).onPause() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2016 The Android Open Source Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<merge xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<com.google.android.exoplayer2.ui.AspectRatioFrameLayout | ||
android:id="@id/exo_content_frame" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_gravity="center"> | ||
|
||
<!-- Video surface will be inserted as the first child of the content frame. --> | ||
<com.otaliastudios.zoom.ZoomSurfaceView | ||
android:id="@+id/player_surface_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:scaleX="1" | ||
android:scaleY="1" | ||
app:maxZoom="6" | ||
app:minZoom="1" | ||
app:minZoomType="zoom" /> | ||
|
||
<View | ||
android:id="@id/exo_shutter" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@android:color/black" /> | ||
|
||
<ImageView | ||
android:id="@id/exo_artwork" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:scaleType="fitXY" /> | ||
|
||
<com.google.android.exoplayer2.ui.SubtitleView | ||
android:id="@id/exo_subtitles" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
<ProgressBar | ||
android:id="@id/exo_buffering" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
android:indeterminate="true" /> | ||
|
||
<TextView | ||
android:id="@id/exo_error_message" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_gravity="center" | ||
android:background="@color/exo_error_message_background_color" | ||
android:gravity="center" | ||
android:padding="16dp" /> | ||
|
||
</com.google.android.exoplayer2.ui.AspectRatioFrameLayout> | ||
|
||
<FrameLayout | ||
android:id="@id/exo_ad_overlay" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
<FrameLayout | ||
android:id="@id/exo_overlay" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
<View | ||
android:id="@id/exo_controller_placeholder" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
</merge> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters