Android Studio videoview透明吗?
Android Studio新手,在应用程序中添加了一个视频,该视频的工作方式与我所希望的一样,但当活动加载且视频等待播放时,我有一个黑色补丁,是否可以删除该补丁以显示活动的背景,或者如果不透明,是否可以使用图像?我尝试过seekTo方法,但由于某些原因,它不起作用 代码使用Android Studio videoview透明吗?,android,android-videoview,Android,Android Videoview,Android Studio新手,在应用程序中添加了一个视频,该视频的工作方式与我所希望的一样,但当活动加载且视频等待播放时,我有一个黑色补丁,是否可以删除该补丁以显示活动的背景,或者如果不透明,是否可以使用图像?我尝试过seekTo方法,但由于某些原因,它不起作用 代码使用 <VideoView android:id="@+id/videoview" android:layout_width="250dp"
<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"
/>
我做错了什么
为了提供帮助--这是活动一开始的样子
这就是我希望“活动”打开时的外观查看以下示例:
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
<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>
请尝试上面的内容,希望这可以帮助您在此处添加错误日志,这会有所帮助。您好,user10030079@,您的意思是在视频开始播放之前有一个(黑色)闪光灯吗?(你解决问题了吗?)。
<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>