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.
Related
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 am trying to play a video from the device on a VideoView. Here is my code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vView = (VideoView) findViewById(R.id.videoView);
mc = new MediaController(this);
vView.setMediaController(mc);
String new_emulator_path = "/storage/emulated/0/Download/testvid.mp4";
Uri uri = Uri.parse(new_emulator_path);
vView.setVideoURI(uri);
vView.requestFocus();
mc.show();
vView.start();
}
...
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/videoView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true" />
While using the same code on 5.1 it plays fine, but does not play in 4.3 and below. Following is the log extract:
04-30 00:28:09.141 2293-2293/com.ebook.video D/MediaPlayer: getMetadata
04-30 00:28:09.249 2293-2314/com.ebook.video E/MediaPlayer: error (1, -2147483648)
04-30 00:28:09.257 2293-2293/com.ebook.video E/MediaPlayer: Error (1,-2147483648)
04-30 00:28:09.257 2293-2293/com.ebook.video D/VideoView: Error: 1,-2147483648
I have seen many threads in regard to this error code, but could not comprehend any explanations.
EDIT: I have tried playing videos of different formats - mkv (H264 mpeg-4 AVC) , 3gp (H263), mp4 (H264 mpeg-4 AVC), flv (FLV1). Video with 3gp extension and H263 format plays fine, while others give the error message as mentioned above. Any ideas on how to resolve this ?
According to Documentation Android not support H265 before android 5.1
So I think you have issue with this. You can use ExoPlayer (Or better way ExoMedia simple wrapper around VideoPlayer & ExoPlayer).
BTW use following piece of code may helps you :
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
videoView.setVideoPath(YOUR_LOCAL_FILE_PATH);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
Log.i(TAG,"Hoooray");
}
});
videoView.start();
As I found out from your code you want to display video in emulator so first see this related post.
Hi i've got problem with streaming. When i'm running video through http it works but i need to run it through rtsp. When application starts i have bar with buttons but time is 0:00 and i haven't got any image. I haven't got any errors like "video can't be played", what should i do?
String SrcPath = "rtsp://v5.cache1.c.youtube.com/CjYLENy73wIaLQnhycnrJQ8qmRMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYPj_hYjnq6uUTQw=/0/0/0/video.3gp";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
myVideoView.setVideoURI(Uri.parse(SrcPath));
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();
}
Ok i found solve. I had such problem because of my tablet, it can't play anything through rtsp, don't know why. On other device it works good.
EDIT:
IT IS FAULT OF ANDROID 2.3.4 i found the information about that and this version of android can't use rtsp. I heard that there is a need to add some decoder. Or just try another version
Am interested in creating own movie which should be started when the button "Start" is clicked. The movie should be played within the app, it should not use the media player or flash player. Is there any ways to play movie without player ?
Thanks in advance.
Try this code
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
videoHolder = new VideoView(this);
videoHolder.setMediaController(new MediaController(this));
setContentView(videoHolder);
// videoHolder.setVideoURI(Uri.parse("file:///sdcard/video.3gp"));
videoHolder.setVideoURI(Uri.parse("file:///sdcard/video.mp4"));
videoHolder.requestFocus();
videoHolder.start();
}
Have you taken a look at the VideoView Class? I believe that this is what you are looking for :)
Simple use videoview. save file in assets and use videoview in main.xml
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();
}