mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +00:00
Make video player in media player control a view stub
This commit is contained in:
parent
d3bf6a1c59
commit
94e2b9e66e
@ -10,11 +10,11 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:contentDescription="@string/media_preview_activity__media_content_description" />
|
android:contentDescription="@string/media_preview_activity__media_content_description" />
|
||||||
|
|
||||||
<org.thoughtcrime.securesms.video.VideoPlayer
|
<ViewStub android:id="@+id/video_player_stub"
|
||||||
android:id="@+id/video_player"
|
android:inflatedId="@+id/video_player"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:visibility="gone"/>
|
android:visibility="gone"
|
||||||
|
android:layout="@layout/media_view_video"/>
|
||||||
|
|
||||||
</merge>
|
</merge>
|
7
res/layout/media_view_video.xml
Normal file
7
res/layout/media_view_video.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<org.thoughtcrime.securesms.video.VideoPlayer
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/video_player"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:visibility="gone"/>
|
@ -16,6 +16,7 @@ import org.thoughtcrime.securesms.R;
|
|||||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||||
import org.thoughtcrime.securesms.mms.VideoSlide;
|
import org.thoughtcrime.securesms.mms.VideoSlide;
|
||||||
|
import org.thoughtcrime.securesms.util.views.Stub;
|
||||||
import org.thoughtcrime.securesms.video.VideoPlayer;
|
import org.thoughtcrime.securesms.video.VideoPlayer;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -23,7 +24,7 @@ import java.io.IOException;
|
|||||||
public class MediaView extends FrameLayout {
|
public class MediaView extends FrameLayout {
|
||||||
|
|
||||||
private ZoomingImageView imageView;
|
private ZoomingImageView imageView;
|
||||||
private VideoPlayer videoView;
|
private Stub<VideoPlayer> videoView;
|
||||||
|
|
||||||
public MediaView(@NonNull Context context) {
|
public MediaView(@NonNull Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@ -50,7 +51,7 @@ public class MediaView extends FrameLayout {
|
|||||||
inflate(getContext(), R.layout.media_view, this);
|
inflate(getContext(), R.layout.media_view, this);
|
||||||
|
|
||||||
this.imageView = findViewById(R.id.image);
|
this.imageView = findViewById(R.id.image);
|
||||||
this.videoView = findViewById(R.id.video_player);
|
this.videoView = new Stub<>(findViewById(R.id.video_player_stub));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(@NonNull MasterSecret masterSecret,
|
public void set(@NonNull MasterSecret masterSecret,
|
||||||
@ -64,24 +65,28 @@ public class MediaView extends FrameLayout {
|
|||||||
{
|
{
|
||||||
if (mediaType.startsWith("image/")) {
|
if (mediaType.startsWith("image/")) {
|
||||||
imageView.setVisibility(View.VISIBLE);
|
imageView.setVisibility(View.VISIBLE);
|
||||||
videoView.setVisibility(View.GONE);
|
if (videoView.resolved()) videoView.get().setVisibility(View.GONE);
|
||||||
imageView.setImageUri(masterSecret, glideRequests, source, mediaType);
|
imageView.setImageUri(masterSecret, glideRequests, source, mediaType);
|
||||||
} else if (mediaType.startsWith("video/")) {
|
} else if (mediaType.startsWith("video/")) {
|
||||||
imageView.setVisibility(View.GONE);
|
imageView.setVisibility(View.GONE);
|
||||||
videoView.setVisibility(View.VISIBLE);
|
videoView.get().setVisibility(View.VISIBLE);
|
||||||
videoView.setWindow(window);
|
videoView.get().setWindow(window);
|
||||||
videoView.setVideoSource(masterSecret, new VideoSlide(getContext(), source, size), autoplay);
|
videoView.get().setVideoSource(masterSecret, new VideoSlide(getContext(), source, size), autoplay);
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Unsupported media type: " + mediaType);
|
throw new IOException("Unsupported media type: " + mediaType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause() {
|
public void pause() {
|
||||||
this.videoView.pause();
|
if (this.videoView.resolved()){
|
||||||
|
this.videoView.get().pause();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanup() {
|
public void cleanup() {
|
||||||
this.imageView.cleanup();
|
this.imageView.cleanup();
|
||||||
this.videoView.cleanup();
|
if (this.videoView.resolved()) {
|
||||||
|
this.videoView.get().cleanup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user