Answer the question
In order to leave comments, you need to log in
Why doesn't VideoView work when developing for android?
Good time of the day.
I am developing an application for android and faced the need to implement video playback from the site (using a link to a video file with a size of up to 100 mb), but when creating a VideoView, both in the visual editor and programmatically, the video is not displayed.
Here is the code:
VideoView VideoPlayer = new VideoView(page.this);
VideoPlayer.setVideoURI(Uri.parse("http://mysite.ru/file.mp4"));
VideoPlayer.setVideoPath("http://mysite.ru/file.mp4");
VideoPlayer.setMediaController(new MediaController(page.this));
VideoPlayer.requestFocus(0);
VideoPlayer.start();
PageCont.addView(VideoPlayer);
VideoPlayer.setMediaController(new MediaController(page.this));
Answer the question
In order to leave comments, you need to log in
How strange everything is with you! Have you tried to see what kind of error you have?
<?xml version="1.0" encoding="utf-8"?>
<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="android.letscoder.xyz.videosolution.MainActivity">
<VideoView
android:id="@+id/video_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
package android.letscoder.xyz.videosolution;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
VideoView mVideoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupVideoView(mVideoView, "http://techslides.com/demos/sample-videos/small.mp4");
}
private void setupVideoView(VideoView videoView, String url) {
videoView = (VideoView) findViewById(R.id.video_view);
MediaController controls = new MediaController(this);
controls.setAnchorView(videoView);
videoView.setMediaController(controls);
videoView.setVideoURI(Uri.parse(url));
videoView.start();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question