Android Studio videoview透明吗?

时间:2018-07-04 05:28:39

标签: android android-videoview

Android Studio的新手,并已将视频放到应用程序中,该视频的运行与我希望的一样,但当加载活动且视频正在等待播放时,我有一个黑色补丁,是否可以删除它,因此背景显示了活动的图像,或者如果不是透明的,那么可以使用图像吗?我尝试了seekTo方法,但由于某些原因无法正常工作。

使用

的代码
    <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 I get

这是我希望活动打开时Would like

的样子

1 个答案:

答案 0 :(得分:0)

检查以下示例:

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>

尝试以上希望对您有帮助