标签:内容 number normal prot code cti 就是 protect 应用程序
/**
* Desc:演示使用TextureView和MediaPlayer播放视频
*
* @author 白乾涛 <p>
* @tag TextureView<p>
* @date 2018/5/22 23:56 <p>
*/
public class TextureViewTestActivity extends Activity implements TextureView.SurfaceTextureListener {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);//取消状态栏
TextureView textureView = new TextureView(this);
textureView.setSurfaceTextureListener(this);
textureView.setRotation(45.0f);//可以像普通View一样使用平移、缩放、旋转等变换操作
textureView.setAlpha(0.5f);
setContentView(textureView);
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Log.i("bqt", "onSurfaceTextureAvailable");// SurfaceTexture准备就绪
if (new Random().nextBoolean()) {
String path = "http://ozvd186ua.bkt.clouddn.com/douyin.mp4";
MediaPlayerManager.getInstance().playUrlMedia(new Surface(surface), path);
} else {
try {
MediaPlayerManager.getInstance().playAssetMedia(new Surface(surface), getAssets().openFd("douyin.mp4"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
Log.i("bqt", "onSurfaceTextureSizeChanged");// SurfaceTexture缓冲大小变化
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Log.i("bqt", "onSurfaceTextureDestroyed");// SurfaceTexture即将被销毁
MediaPlayerManager.getInstance().stopMedia();
return true;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
//Log.i("bqt", "onSurfaceTextureUpdated");// SurfaceTexture通过updateImage更新
}
}
/**
* Desc:演示使用TextureView和MediaPlayer播放视频
*
* @author 白乾涛 <p>
* @tag TextureView<p>
* @date 2018/5/22 23:56 <p>
*/
public class TextureViewTestActivity extends Activity implements TextureView.SurfaceTextureListener {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);//取消状态栏
TextureView textureView = new TextureView(this);
textureView.setSurfaceTextureListener(this);
textureView.setRotation(45.0f);//可以像普通View一样使用平移、缩放、旋转等变换操作
textureView.setAlpha(0.5f);
setContentView(textureView);
}
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Log.i("bqt", "onSurfaceTextureAvailable");// SurfaceTexture准备就绪
if (new Random().nextBoolean()) {
String path = "http://ozvd186ua.bkt.clouddn.com/douyin.mp4";
MediaPlayerManager.getInstance().playUrlMedia(new Surface(surface), path);
} else {
try {
MediaPlayerManager.getInstance().playAssetMedia(new Surface(surface), getAssets().openFd("douyin.mp4"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
Log.i("bqt", "onSurfaceTextureSizeChanged");// SurfaceTexture缓冲大小变化
}
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Log.i("bqt", "onSurfaceTextureDestroyed");// SurfaceTexture即将被销毁
MediaPlayerManager.getInstance().stopMedia();
return true;
}
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
//Log.i("bqt", "onSurfaceTextureUpdated");// SurfaceTexture通过updateImage更新
}
}
public class MediaPlayerManager {
private MediaPlayer mPlayer;
private static MediaPlayerManager instance = new MediaPlayerManager();
private MediaPlayerManager() {//构造方法私有
}
public static MediaPlayerManager getInstance() {
return instance;
}
/**
* 播放网络或本地中的Media资源
*/
public void playUrlMedia(Surface surface, String mediaPath) {
try {
if (mPlayer == null) {
mPlayer = new MediaPlayer();
mPlayer.setDataSource(mediaPath);
} else {
if (mPlayer.isPlaying()) {
mPlayer.stop();
}
mPlayer.reset();
mPlayer.setDataSource(mediaPath);
}
mPlayer.setSurface(surface);
mPlayer.setVolume(0.5f, 0.5f);
mPlayer.setLooping(true);
mPlayer.prepareAsync();
mPlayer.setOnPreparedListener(MediaPlayer::start);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 播放Asset中的Media资源
*/
public void playAssetMedia(Surface surface, AssetFileDescriptor fileDescriptor) {
try {
if (mPlayer == null) {
mPlayer = new MediaPlayer();
mPlayer.setDataSource(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(), fileDescriptor.getDeclaredLength());
} else {
if (mPlayer.isPlaying()) {
mPlayer.stop();
}
mPlayer.reset();
mPlayer.setDataSource(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(), fileDescriptor.getDeclaredLength());
}
mPlayer.setSurface(surface);
mPlayer.setVolume(0.5f, 0.5f);
mPlayer.setLooping(true);
mPlayer.prepareAsync();
mPlayer.setOnPreparedListener(MediaPlayer::start);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 停止播放Media
*/
public void stopMedia() {
try {
if (mPlayer != null) {
if (mPlayer.isPlaying()) {
mPlayer.stop();
}
mPlayer.release();
mPlayer = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class MediaPlayerManager {
private MediaPlayer mPlayer;
private static MediaPlayerManager instance = new MediaPlayerManager();
private MediaPlayerManager() {//构造方法私有
}
public static MediaPlayerManager getInstance() {
return instance;
}
/**
* 播放网络或本地中的Media资源
*/
public void playUrlMedia(Surface surface, String mediaPath) {
try {
if (mPlayer == null) {
mPlayer = new MediaPlayer();
mPlayer.setDataSource(mediaPath);
} else {
if (mPlayer.isPlaying()) {
mPlayer.stop();
}
mPlayer.reset();
mPlayer.setDataSource(mediaPath);
}
mPlayer.setSurface(surface);
mPlayer.setVolume(0.5f, 0.5f);
mPlayer.setLooping(true);
mPlayer.prepareAsync();
mPlayer.setOnPreparedListener(MediaPlayer::start);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 播放Asset中的Media资源
*/
public void playAssetMedia(Surface surface, AssetFileDescriptor fileDescriptor) {
try {
if (mPlayer == null) {
mPlayer = new MediaPlayer();
mPlayer.setDataSource(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(), fileDescriptor.getDeclaredLength());
} else {
if (mPlayer.isPlaying()) {
mPlayer.stop();
}
mPlayer.reset();
mPlayer.setDataSource(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(), fileDescriptor.getDeclaredLength());
}
mPlayer.setSurface(surface);
mPlayer.setVolume(0.5f, 0.5f);
mPlayer.setLooping(true);
mPlayer.prepareAsync();
mPlayer.setOnPreparedListener(MediaPlayer::start);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 停止播放Media
*/
public void stopMedia() {
try {
if (mPlayer != null) {
if (mPlayer.isPlaying()) {
mPlayer.stop();
}
mPlayer.release();
mPlayer = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* Desc:演示使用TextureView和Camera预览拍照
*
* @author 白乾涛 <p>
* @tag TextureView<p>
* @date 2018/5/22 23:56 <p>
*/
public class TextureViewTestActivity extends Activity implements TextureView.SurfaceTextureListener {
private Camera mCamera;//权限【android.permission.CAMERA】
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);//取消状态栏
TextureView mTextureView = new TextureView(this);
mTextureView.setSurfaceTextureListener(this);
mTextureView.setRotation(45.0f);//可以像普通View一样使用平移、缩放、旋转等变换操作
mTextureView.setAlpha(0.5f);
setContentView(mTextureView);
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Log.i("bqt", "onSurfaceTextureAvailable");// SurfaceTexture准备就绪
try {
mCamera = Camera.open();//如果提示【Fail to connect to camera service】很可能是没申请权限,或申请权限了单用户没有给你权限
mCamera.setPreviewTexture(surface);
mCamera.startPreview();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
Log.i("bqt", "onSurfaceTextureSizeChanged");// SurfaceTexture缓冲大小变化
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Log.i("bqt", "onSurfaceTextureDestroyed");// SurfaceTexture即将被销毁
mCamera.stopPreview();
mCamera.release();
return true;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
//Log.i("bqt", "onSurfaceTextureUpdated");// SurfaceTexture通过updateImage更新
}
}
/**
* Desc:演示使用TextureView和Camera预览拍照
*
* @author 白乾涛 <p>
* @tag TextureView<p>
* @date 2018/5/22 23:56 <p>
*/
public class TextureViewTestActivity extends Activity implements TextureView.SurfaceTextureListener {
private Camera mCamera;//权限【android.permission.CAMERA】
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);//取消状态栏
TextureView mTextureView = new TextureView(this);
mTextureView.setSurfaceTextureListener(this);
mTextureView.setRotation(45.0f);//可以像普通View一样使用平移、缩放、旋转等变换操作
mTextureView.setAlpha(0.5f);
setContentView(mTextureView);
}
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Log.i("bqt", "onSurfaceTextureAvailable");// SurfaceTexture准备就绪
try {
mCamera = Camera.open();//如果提示【Fail to connect to camera service】很可能是没申请权限,或申请权限了单用户没有给你权限
mCamera.setPreviewTexture(surface);
mCamera.startPreview();
} catch (IOException e) {
e.printStackTrace();
}
}
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
Log.i("bqt", "onSurfaceTextureSizeChanged");// SurfaceTexture缓冲大小变化
}
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Log.i("bqt", "onSurfaceTextureDestroyed");// SurfaceTexture即将被销毁
mCamera.stopPreview();
mCamera.release();
return true;
}
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
//Log.i("bqt", "onSurfaceTextureUpdated");// SurfaceTexture通过updateImage更新
}
}
标签:内容 number normal prot code cti 就是 protect 应用程序
原文地址:https://www.cnblogs.com/baiqiantao/p/299570dc16f00c0ad12de306613e449f.html