-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from ashqal/surface-no-destroy
Preserve EGLContext OnPause
- Loading branch information
Showing
10 changed files
with
168 additions
and
5 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
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
119 changes: 119 additions & 0 deletions
119
app/src/main/java/com/asha/md360player4android/IjkPlayerDemoActivity.java
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,119 @@ | ||
package com.asha.md360player4android; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.graphics.SurfaceTexture; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.view.Surface; | ||
import android.view.TextureView; | ||
import android.view.View; | ||
import android.view.Window; | ||
import android.view.WindowManager; | ||
|
||
import tv.danmaku.ijk.media.player.IMediaPlayer; | ||
|
||
|
||
/** | ||
* Created by hzqiujiadi on 16/7/6. | ||
* hzqiujiadi [email protected] | ||
*/ | ||
public class IjkPlayerDemoActivity extends Activity implements TextureView.SurfaceTextureListener { | ||
|
||
private Surface surface; | ||
|
||
private MediaPlayerWrapper mMediaPlayerWrapper = new MediaPlayerWrapper(); | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
// no title | ||
requestWindowFeature(Window.FEATURE_NO_TITLE); | ||
|
||
// full screen | ||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, | ||
WindowManager.LayoutParams.FLAG_FULLSCREEN); | ||
|
||
setContentView(R.layout.activity_ijkdemo); | ||
|
||
mMediaPlayerWrapper.init(); | ||
mMediaPlayerWrapper.setPreparedListener(new IMediaPlayer.OnPreparedListener() { | ||
@Override | ||
public void onPrepared(IMediaPlayer mp) { | ||
cancelBusy(); | ||
} | ||
}); | ||
|
||
TextureView textureView = (TextureView) findViewById(R.id.video_view); | ||
textureView.setSurfaceTextureListener(this); | ||
|
||
Uri uri = getUri(); | ||
if (uri != null){ | ||
mMediaPlayerWrapper.openRemoteFile(uri.toString()); | ||
mMediaPlayerWrapper.prepare(); | ||
} | ||
|
||
} | ||
|
||
public static void start(Context context, Uri uri){ | ||
Intent i = new Intent(context,IjkPlayerDemoActivity.class); | ||
i.setData(uri); | ||
context.startActivity(i); | ||
} | ||
|
||
protected Uri getUri() { | ||
Intent i = getIntent(); | ||
if (i == null || i.getData() == null){ | ||
return null; | ||
} | ||
return i.getData(); | ||
} | ||
|
||
@Override | ||
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) { | ||
surface = new Surface(surfaceTexture); | ||
mMediaPlayerWrapper.getPlayer().setSurface(surface); | ||
|
||
} | ||
|
||
@Override | ||
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { | ||
|
||
} | ||
|
||
@Override | ||
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { | ||
mMediaPlayerWrapper.getPlayer().setSurface(null); | ||
this.surface = null; | ||
return true; | ||
} | ||
|
||
@Override | ||
public void onSurfaceTextureUpdated(SurfaceTexture surface) { | ||
|
||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
mMediaPlayerWrapper.onDestroy(); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
mMediaPlayerWrapper.onPause(); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
mMediaPlayerWrapper.onResume(); | ||
} | ||
|
||
public void cancelBusy(){ | ||
findViewById(R.id.progress).setVisibility(View.GONE); | ||
} | ||
} |
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
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,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" android:layout_height="match_parent"> | ||
<TextureView | ||
android:id="@+id/video_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
<ProgressBar | ||
android:layout_centerInParent="true" | ||
android:id="@+id/progress" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" /> | ||
</FrameLayout> |
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
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