[英]Android Studio videoview transparent?
New to Android Studio and have put a video in the application which work just as I wish except when the activity is loaded and the video is waiting to be played I have a black patch, is it possible to remove this so the background of the activity is shown or if not transparent then can an image be used? 这是Android Studio的新功能,并已将视频放入应用程序中,该视频的运行方式与我希望的一样,但当活动加载且视频正在等待播放时,我有一个黑色补丁,是否可以删除此视频,因此活动背景是否显示或如果不透明则可以使用图像吗? I have tried the seekTo method but for some reason does not work.
我尝试了seekTo方法,但由于某些原因无法正常工作。
Code using 代码使用
<VideoView
android:id="@+id/videoview"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:layout_marginEnd="0sp"
android:layout_marginLeft="0sp"
android:layout_marginRight="0sp"
android:layout_marginStart="0sp"
/>
Java 爪哇
public void onButtonClick(View v) {
VideoView videoview = findViewById(R.id.videoview);
Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.kmeet);
videoview.setVideoURI(uri);
videoview.seekTo(100);
videoview.start();
What have I got wrong ? 我怎么了?
To help -- This is what the activity looks like as soon as opens, What I get 帮助-这是活动一打开即看起来的样子, 我得到了什么
This is what I would like it to look like when activity opens Would like 这是我希望活动打开时的样子
Check below example: 检查以下示例:
MainActivity.java MainActivity.java
package example.pranavdemo.videoviewexample;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.res.Configuration;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
public class MainActivity extends Activity {
VideoView simpleVideoView;
MediaController mediaControls;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Find your VideoView in your video_main.xml layout
simpleVideoView = (VideoView) findViewById(R.id.simpleVideoView);
if (mediaControls == null) {
// create an object of media controller class
mediaControls = new MediaController(MainActivity.this);
mediaControls.setAnchorView(simpleVideoView);
}
// set the media controller for video view
simpleVideoView.setMediaController(mediaControls);
// set the uri for the video view
simpleVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.fishvideo));
// start a video
simpleVideoView.start();
// implement on completion listener on video view
simpleVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Toast.makeText(getApplicationContext(), "Thank You...!!!", Toast.LENGTH_LONG).show(); // display a toast when an video is completed
}
});
simpleVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Toast.makeText(getApplicationContext(), "Oops An Error Occur While Playing Video...!!!", Toast.LENGTH_LONG).show(); // display a toast when an error is occured while playing an video
return false;
}
});
}
}
main.xml main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<VideoView
android:id="@+id/simpleVideoView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Try above hope this may help you 尝试以上希望对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.