use of android.widget.VideoView in project android_frameworks_base by crdroidandroid.
the class VideoViewCaptureActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mVideoView = new VideoView(this);
mVideoView.setOnPreparedListener(mp -> {
mp.setLooping(true);
mVideoWidth = mp.getVideoWidth();
mVideoHeight = mp.getVideoHeight();
mVideoView.start();
});
Uri uri = Uri.parse("android.resource://com.android.test.hwui/" + R.raw.colorgrid_video);
mVideoView.setVideoURI(uri);
Button button = new Button(this);
button.setText("Copy bitmap to /sdcard/surfaceview.png");
button.setOnClickListener((View v) -> {
final Bitmap b = Bitmap.createBitmap(mVideoWidth, mVideoHeight, Bitmap.Config.ARGB_8888);
PixelCopy.request(mVideoView, b, (int result) -> {
if (result != PixelCopy.SUCCESS) {
Toast.makeText(VideoViewCaptureActivity.this, "Failed to copy", Toast.LENGTH_SHORT).show();
return;
}
try {
try (FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/surfaceview.png")) {
b.compress(Bitmap.CompressFormat.PNG, 100, out);
}
} catch (Exception e) {
// Ignore
}
}, mVideoView.getHandler());
});
FrameLayout content = new FrameLayout(this);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(button, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layout.addView(mVideoView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
content.addView(layout, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
setContentView(content);
}
use of android.widget.VideoView in project platform_frameworks_base by android.
the class VideoViewCaptureActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mVideoView = new VideoView(this);
mVideoView.setOnPreparedListener(mp -> {
mp.setLooping(true);
mVideoWidth = mp.getVideoWidth();
mVideoHeight = mp.getVideoHeight();
mVideoView.start();
});
Uri uri = Uri.parse("android.resource://com.android.test.hwui/" + R.raw.colorgrid_video);
mVideoView.setVideoURI(uri);
Button button = new Button(this);
button.setText("Copy bitmap to /sdcard/surfaceview.png");
button.setOnClickListener((View v) -> {
final Bitmap b = Bitmap.createBitmap(mVideoWidth, mVideoHeight, Bitmap.Config.ARGB_8888);
PixelCopy.request(mVideoView, b, (int result) -> {
if (result != PixelCopy.SUCCESS) {
Toast.makeText(VideoViewCaptureActivity.this, "Failed to copy", Toast.LENGTH_SHORT).show();
return;
}
try {
try (FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/surfaceview.png")) {
b.compress(Bitmap.CompressFormat.PNG, 100, out);
}
} catch (Exception e) {
// Ignore
}
}, mVideoView.getHandler());
});
FrameLayout content = new FrameLayout(this);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(button, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layout.addView(mVideoView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
content.addView(layout, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
setContentView(content);
}
use of android.widget.VideoView in project krypton-android by kryptco.
the class GeneratingFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_generating, container, false);
final View animationContainer = root.findViewById(R.id.animationContainer);
this.anim = (VideoView) root.findViewById(R.id.generateAnimation);
final VideoView anim = this.anim;
anim.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
anim.post(new Runnable() {
@Override
public void run() {
anim.start();
}
});
}
});
anim.setOnInfoListener(new MediaPlayer.OnInfoListener() {
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
// video started
animationContainer.setVisibility(View.VISIBLE);
return true;
}
return false;
}
});
anim.setVideoURI(Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + R.raw.generate_animation));
anim.seekTo(0);
return root;
}
use of android.widget.VideoView in project tlplib by tinylabproductions.
the class AndroidVideoPlayer method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.media_player_layout);
VideoView videoView = (VideoView) findViewById(R.id.video_display);
Button closeButton = (Button) findViewById(R.id.close_button);
// This is needed so the listener wouldn't change if for some reason new Activity was created before closing the first one
final VideoPlayerListener listenerInstance = listener;
Intent intent = getIntent();
final String fileName = intent.getStringExtra(FILE_NAME);
final String urlToOpen = intent.getStringExtra(URL_TO_OPEN);
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
if (listenerInstance != null)
listenerInstance.onVideoComplete();
openUrl(urlToOpen);
}
});
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listenerInstance != null)
listenerInstance.onCancel();
closeActivity();
}
});
videoView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (listenerInstance != null)
listenerInstance.onVideoClick();
openUrl(urlToOpen);
return true;
}
});
File file = extractFromResource("/assets/" + fileName);
if (file != null) {
videoView.setVideoPath(file.getAbsolutePath());
videoView.requestFocus();
videoView.start();
} else
closeActivity();
}
use of android.widget.VideoView in project mytarget-android by myTargetSDK.
the class InstreamAdActivity method startVideo.
public void startVideo(View view) {
if (instreamAd == null)
return;
videoView = new VideoView(this);
FrameLayout.LayoutParams videoPlayerParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
videoPlayerParams.gravity = Gravity.CENTER;
videoFrame.addView(videoView, videoPlayerParams);
playButton.setVisibility(View.GONE);
FrameLayout.LayoutParams adPlayerParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
adPlayerParams.gravity = Gravity.CENTER;
View adPlayerView = instreamAd.getPlayer().getView();
if (adPlayerView.getParent() == null)
videoFrame.addView(adPlayerView, adPlayerParams);
instreamAdController.setSkipListener(this);
instreamAdController.setAdClickListener(this);
instreamAdController.setAnchorView(videoFrame);
instreamAdController.setVisibility(View.VISIBLE);
startPreroll();
}
Aggregations