Skip to content
Permalink
Browse files

still improving

  • Loading branch information
AsynctaskCoffee committed Aug 17, 2019
1 parent bd96d89 commit ee38e509608c4d80706cf41ae7b8fe1e5e647c9a
@@ -2,11 +2,25 @@ package egolabsapps.basicodemine.videolayout

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.FrameLayout

class Main2Activity : AppCompatActivity() {
lateinit var frameLayout: FrameLayout
lateinit var videoLayout: VideoLayout

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main2)
initViews()
}


fun initViews() {
frameLayout = findViewById(R.id.frameLayout)
videoLayout = VideoLayout(this)
videoLayout.setGravity(VideoLayout.VGravity.centerCrop)
videoLayout.setIsLoop(true)
videoLayout.setPathOrUrl("loginvideotype3.mp4")
frameLayout.addView(videoLayout)
}
}
@@ -3,6 +3,7 @@ package egolabsapps.basicodemine.videolayout
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.view.View
import android.view.Window
import android.view.WindowManager
@@ -18,6 +19,11 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)
supportActionBar?.hide()
videoLayout = findViewById(R.id.videoLayout)
Handler().postDelayed({

videoLayout.setPathOrUrl("loginvideotype4.mp4")

}, 4000)
}

fun thanks(v: View) {
@@ -3,6 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/frameLayout"
android:layout_height="match_parent"
tools:context=".Main2Activity">

@@ -52,6 +52,10 @@ public int getValue() {
}
}

public VideoLayout(@NonNull Context context) {
super(context);
}

public VideoLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);

@@ -166,21 +170,45 @@ private void surfaceAvaibleWorkers(SurfaceTexture surfaceTexture, int width, int
mMediaPlayer.prepareAsync();
mMediaPlayer.setOnPreparedListener(MediaPlayer::start);

} catch (IllegalArgumentException e) {
Log.d(TAG, e.getMessage());
// e.printStackTrace();
} catch (SecurityException e) {
Log.d(TAG, e.getMessage());
// e.printStackTrace();
} catch (IllegalStateException e) {
Log.d(TAG, e.getMessage());
// e.printStackTrace();
} catch (IOException e) {
Log.d(TAG, e.getMessage());
// e.printStackTrace();
} catch (IllegalArgumentException ignored) {

} catch (SecurityException ignored) {

} catch (IllegalStateException ignored) {

} catch (IOException ignored) {

}
}

//todo video değiştirme kısmının kontrol ve testlerini yap

private void changeVideo() {
try {
onDestroyVideoLayout();
mMediaPlayer = new MediaPlayer();
if (isUrl)
mMediaPlayer.setDataSource(FILE_NAME);
else {
AssetFileDescriptor afd = getContext().getAssets().openFd(FILE_NAME);
mMediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
}
mMediaPlayer.setVolume(0f, 0f);
mMediaPlayer.setLooping(IS_LOOP);
mMediaPlayer.setSurface(new Surface(videoSurface.getSurfaceTexture()));
mMediaPlayer.prepareAsync();
mMediaPlayer.setOnPreparedListener(MediaPlayer::start);

} catch (IllegalArgumentException ignored) {

} catch (SecurityException ignored) {

} catch (IllegalStateException ignored) {

} catch (IOException ignored) {

}
}

@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
@@ -220,17 +248,17 @@ public void onResumeVideoLayout() {
if (mMediaPlayer != null && !mMediaPlayer.isPlaying())
try {
mMediaPlayer.start();
} catch (IllegalStateException e) {
Log.d(TAG, e.getMessage());
} catch (IllegalStateException ignored) {

}
}

public void onPauseVideoLayout() {
if (mMediaPlayer != null && mMediaPlayer.isPlaying())
try {
mMediaPlayer.pause();
} catch (IllegalStateException e) {
Log.d(TAG, e.getMessage());
} catch (IllegalStateException ignored) {

}
}

@@ -244,6 +272,23 @@ public TextureView getVideoSurface() {

public void setPathOrUrl(String FILE_NAME) {
this.FILE_NAME = FILE_NAME;

isUrl = FILE_NAME.contains("http://") || FILE_NAME.contains("https://");

if (videoSurface == null) {
initViews();
addView(videoSurface);
setListeners();
}

if (VIDEO_GRAVITY != 3) {
calculateVideoSize();
surfaceSetup();
}

if (videoSurface != null) {
changeVideo();
}
}

public void setIsLoop(boolean IS_LOOP) {

0 comments on commit ee38e50

Please sign in to comment.
You can’t perform that action at this time.