I want to play video inside my webview. I have examined different example but my HTML a bit different.
{\"mp4\":[{\"name\":\"240\",\"file\":\"http:\\\/\\\/xxxx.xxxx.net\\\/lt\\\/2016\\\/04\\\/24\\\/test_320x240.mp4\",\"type\":\"video\\\/mp4\"}
I can download HTML code and used function;
webview.loadData(myHTML,"text/html; charset=UTF-8", null);)
However, I can't display videos in my application. Thank you for helping.
You can try playing the video using VideoView rather than trying to load it in a webview.Below is the sample code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = (VideoView) findViewById(R.id.videoView);
File file = new File(Environment.getExternalStorageDirectory(), "rhyme.mp4");
videoView.setVideoPath(file.getAbsolutePath());
videoView.setMediaController(new MediaController(this));
videoView.start();
}
Also if you want to stream some video files from internet, you can go ahead with ExoPlayer. Here is the link
Kindly mark this reply as answer if it solves your problem.
I have got this code, which works great for playing one video from http:
public class MainActivity extends Activity {
private VideoView mVideoView;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
Toast.makeText(this,"Loading",Toast.LENGTH_LONG).show();
mVideoView = (VideoView) findViewById(R.id.surface_view);
mVideoView.setVideoURI(Uri.parse("http://some_url/movie1.mp4"));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.start();
}
}
What I need to do is to play two or three different videos in a row, but without (or with as small as possible) gap between them.
I thought about checking current video buffer state and when it hits 100%, start in background buffering another video (video one is still playing in foreground). After video one stops playing I would like to i.e. switch instances or buffers and start playing video two.
Is it possible, and if it is can anyone give me a hint about how to code it?
Thanks
I try to use VLC to Streaming a video to my android phone
here is my code
public class VideoMain extends Activity {
VideoView myVideoView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_main);
VideoView myVideoView = (VideoView)findViewById(R.id.videoView1);
myVideoView.setVideoPath("http://140.118.208.220:8080");
myVideoView.setMediaController(new MediaController(this));
}
and the I use VLC streaming wizard->streaming to network->myVideo->HTTP->MPEG2->FINISH
But it seem to not work at all
please help my solve this:)
Android supports 3GPP (.3gp) and MPEG-4 (.mp4) no MPEG-2 in video for more detail see Android Developer Media Formats.
how do i reference a video and play it using mediaPlayer and VideoViewer, when the file is in my raw folder
iv tried
videoview.setVideoPath("android.raw://com.example.movievp8");
as well as
MediaPlayer video1 = MediaPlayer.create(this, R.raw.movievp8);
once I have referenced it should i just hit video1.start();
also does anyone know where i could get like a full sample code on how to use media player for videos, just the basics.
Your code
MediaPlayer video1 = MediaPlayer.create(this, R.raw.movievp8);
video1.start();
should works (but you will only have audio).
One way to do it is using a VideoView (where your video will be displayed) and a MediaController (to have some predefined buttons such as Play, pause, stop, etc.)
VideoView vv = (VideoView) findViewById(R.id.videoview);
MediaController controller = new MediaController(vv.getContext());
vv.setMediaController(controller);
vv.setVideoURI(Uri.parse("android.resource://" + context.getPackageName() + "/" + videoID));
vv.start();
Remember that the simulator doesn't support video. You'll need to use a real device for testing video.
I'm trying to stream a video from VLC to an HTC G1. After several "this should work" I found a sout-chain that allowed me to watch the stream via VLC. I am also able to hear the audio on the android.
The sout-chain I'm currently using:
vlc some_file.mp4 -I http --sout "#transcode{soverlay,ab=128,samplerate=44100,channels=2,acodec=mp4a,vcodec=h264,width=480,height=270,vfilter="canvas{width=480,height=270,aspect=16:9}",fps=25,vb=800,venc=x264{level=12,no-cabac,subme=20,threads=4,bframes=0,min-keyint=1,keyint=50}}:gather:rtp{mp4a-latm,sdp=rtsp://0.0.0.0:5554/stream.sdp}"
That's what I'm doing on the droid:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
vv = (VideoView) findViewById(R.id.video_view);
vv.setVideoURI(Uri.parse("rtsp://<local_ip>:5554/stream.sdp"));
vv.start();
}
I tried to keep it as minimal as possible (this is actually an example I found in another thread here).
I also tried using MediaPlayer:
MediaPlayer mp = MediaPlayer.create(this, Uri.parse("rtsp://<local_ip>:5554/stream.sdp"));
mp.setDisplay(vv.getHolder());
mp.start();
I use setDisplay(SurfaceHolder) cause someone mentioned MediaPlayer otherwise wont know what display to use.
Any idea what I'm missing or doing wrong?
Edit: I hinted the the file with MP4Box
First, I think there's problem with your audio encoder, it shows "MPEG-1/2 Video" is not an audio encoder, would you please try "mpga"?
and another problem is you are trying to fit the frames into a specified size, width=480,height=270, could you delete this part?
my command works:
vlc /Users/chenyu/Sites/BBC.mp4 -I http --sout "#transcode{soverlay,ab=128,samplerate=44100,channels=2,acodec=mpga,vcodec=h264,fps=25,vb=800,venc=x264{level=1,no-cabac,subme=20,threads=4,bframes=0,min-keyint=1,keyint=50}}:gather:rtp{mp4a-latm,sdp=rtsp://10.0.1.2:5554/stream.sdp}"
also could you try the following code on android side?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final VideoView vidView = (VideoView)findViewById(R.id.myVideo);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(vidView);
vidView.setMediaController(vidControl);
vidView.setVideoPath("rtsp://10.0.1.2:5554/stream.sdp");
vidView.start();
}