简体   繁体   English

视频未使用 VideoView 中的链接播放

[英]Video is not playing using link in VideoView

All the code here is fine, but through the link I used no videos can be viewed.这里的所有代码都很好,但是通过我使用的链接无法查看视频。 No videos can be viewed on my apps.无法在我的应用上查看视频。

This Code is Run.此代码正在运行。 Then Result Is.然后结果是。 See This Image on Click点击查看此图片

XML: XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <VideoView
        android:id="@+id/VideoView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="button" />
</RelativeLayout>

Can not working both also code.不能同时工作也代码。 Result is:结果是:

https://i.stack.imgur.com/RztTg.jpg https://i.stack.imgur.com/RztTg.jpg

JAVA:爪哇:

public class VideoViewActivity extends Activity {

    // Declare variables
    ProgressDialog pDialog;
    VideoView videoview;
    Button button;

    // Insert your Video URL

    String VideoURL = "https://firebasestorage.googleapis.com/v0/b/myapplication-93934.appspot.com/o/4zHm_6AQ7CY_mp4-hd.mp4?alt=media&token=a31e1e60-7104-4060-8112-1527ab58fe3a";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.videoview_main);
        videoview = (VideoView) findViewById(R.id.VideoView);


        pDialog = new ProgressDialog(VideoViewActivity.this);
        pDialog.setTitle("Android Video Streaming Tutorial");
        pDialog.setMessage("Buffering...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);

        pDialog.show();

        try {

            MediaController mediacontroller = new MediaController(
                    VideoViewActivity.this);
            mediacontroller.setAnchorView(videoview);
            Uri video = Uri.parse(VideoURL);
            videoview.setMediaController(mediacontroller);
            videoview.setVideoURI(video);

        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }

        videoview.requestFocus();
        videoview.setOnPreparedListener(new OnPreparedListener() {
            // Close the progress bar and play the video
            public void onPrepared(MediaPlayer mp) {
                pDialog.dismiss();
                videoview.start();
            }
        });

    }

}

Add the INTERNET permission into your manifest file if you haven't put it.如果您还没有将 INTERNET 权限添加到您的清单文件中。

<uses-permission android:name="android.permission.INTERNET"/>

and try this code并尝试此代码

import android.app.ProgressDialog;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.widget.VideoView;
import androidx.appcompat.app.AppCompatActivity;

public class VideoActivity extends AppCompatActivity {

    String VideoURL = "https://firebasestorage.googleapis.com/v0/b/myapplication-93934.appspot.com/o/4zHm_6AQ7CY_mp4-hd.mp4?alt=media&token=a31e1e60-7104-4060-8112-1527ab58fe3a";
    ProgressDialog pDialog;
    VideoView videoview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);

        videoview=findViewById(R.id.VideoView);
        pDialog = new ProgressDialog(VideoActivity.this);
        pDialog.setTitle("Android Video Streaming Tutorial");
        pDialog.setMessage("Buffering...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);

        pDialog.show();

        videoview.setVideoPath(VideoURL);

        videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                pDialog.dismiss();
                videoview.start();
            }
        });

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM