Reputation: 21
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:
<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.sstatic.net/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();
}
});
}
}
Upvotes: 2
Views: 97
Reputation: 152
Add the INTERNET permission into your manifest file if you haven't put it.
<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();
}
});
}
}
Upvotes: 1