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.
This is a very weird problem. I know that I probably miss something fundamental, but I could not find any explanation after diligent search.
The weird problem is the following:
An app generates a video file (foo.mp4).
It starts another activity to play this file (see code below).
The video play file play activity displays error message: "Can't play this video"
Leave this activity (e.g. by tapping the home key).
Go back to the app, and the video plays perfectly.
The above is 100% reproducible.
The following is the code (this is not the production code, but it is the actual code used to reproduce the problem.)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play_video_file);
VideoView videoView = (VideoView) findViewById(R.id.videoView);
videoView.setVideoPath(getIntent().getStringExtra("file_path"));
}
protected void onResume() {
VideoView videoView = (VideoView) findViewById(R.id.videoView);
videoView.start();
super.onResume();
};
The file path is: /storage/sdcard0/Movies/MyApp/foo.mp4
Some may think at this point that a waiting period is needed before playing after the file is created. I have tried waiting for 2 minutes after the file's writing stream is closed and before the video file play activity is started. The outcome is exactly the same.
Im trying to understand how to add video to my application using the VideoView container but so far I've never been able to view a video and all i receive is an error 'Can't play this video'.
I have a simple method that load's the video:-
private void setupVideo() {
VideoView videoView = (VideoView)findViewById(R.id.videoView);
videoView.setVideoPath("video/Test_Movie.m4v");
videoView.start();
}
I have tried converting the video to many H264, H263 , 3gp formats but I can find anything that works.I even have downloaded a video that said worked in a book i have but still doesn't work.
any help appreciated!
thx.
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.
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();
}