Android VideoView not working in sdk 4.3 - android

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.

Related

Error : avformat_open_input: Protocol not found : -1330794744

I am building an android stream player using Vitamio.
Here is my codes:
mVideoView = (VideoView) findViewById(R.id.videoView);
path = "https://www.youtube.com/watch?v=vic5gj2qXKg";
mVideoView.setVideoPath(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.setPlaybackSpeed(1.0f);
}
});
But it returns ERROR:
avformat_open_input: Protocol not found : -1330794744
error (1, -1330794744)
I think this error is related to FFMpeg for Vitamio.
Who can solve this problem?
Thank you.
It appears when ffmpeg does not support streaming format, or not initialized by "avformat_network_init()"
See if you can find whether Vitamio supports network format or not, or some function to initialize.
Youtube videos links can be play via only Youtube Android Player API. Download Jar from here: https://developers.google.com/youtube/android/player/downloads/

RTSP video link is not playing smoothly in android

I am trying to build an android app that will stream video from RTSP web link. I have used vitamio library and video is streaming but the problem is, it is not streaming smoothly. Playback speed changes while streaming.
How to get rid from this?
Code is given below,
videoView = (VideoView) findViewById(R.id.VideoView);
videoView.setVideoURI(Uri.parse(liveUrl));
videoView.setOnBufferingUpdateListener(this);
videoView.setOnCompletionListener(this);
videoView.setOnCompletionListener(this);
videoView.setOnPreparedListener(this);
MediaController mediaController = new MediaController(this);
videoView.setMediaController(mediaController);
videoView.start();
videoView.setVideoQuality(-16);
videoView.setBufferSize(2048);
videoView.requestFocus();

Google TV VideoView playing YouTube rtsp videos

I am accessing a video link via the YouTube API thusly:
JSONObject(videoString).getJSONObject("entry")
.getJSONObject("media$group").getJSONArray("media$content")
.getJSONObject(0).getString("url");
Which gives me a link to a video such as:
rtsp://v7.cache5.c.youtube.com/CiILENy73wIaGQlXg0iXvlQ9SBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp
I then try to play the video with:
mVideoView.setVideoURI(result);
final MediaController mediaController = new MediaController(mActivity);
mVideoView.setMediaController(mediaController);
mVideoView.requestFocus();
mVideoView.start();
This works fine on my tablet running ICS but doesn't seem to work on GoogleTV, is there something I need to do specifically for GTV in this instance?
Logcat output:
04-30 14:03:41.212: D/MediaPlayer(1132): Couldn't open file on client side, trying server side
04-30 14:03:41.308: D/dalvikvm(1132): GC_CONCURRENT freed 862K, 13% free 8303K/9479K, paused 0ms+2ms
04-30 14:03:51.920: E/MediaPlayer(1132): error (1, -2147483648)
04-30 14:03:51.920: E/MediaPlayer(1132): Error (1,-2147483648)
04-30 14:03:51.920: D/VideoView(1132): Error: 1,-2147483648
I verified that VideoView playing YouTube RTSP video works on Google TV:
String vURL = "rtsp://v5.cache1.c.youtube.com/CjYLENy73wIaLQnhycnrJQ8qmRMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYPj_hYjnq6uUTQw=/0/0/0/video.3gp";
mVideoView = (VideoView)this.findViewById(R.id.myvideoview);
mVideoView.setVideoURI(Uri.parse(vURL));
final MediaController mediaController = new MediaController(this);
mVideoView.setMediaController(mediaController);
mVideoView.requestFocus();
mVideoView.start();
Only thing I changed was parsing a different URL. Try this working URL in your code then.

Opening RTSP video in VideoView

I wan't to open a .3gp video that is hosted on a remote server in a VideoView inside my app. The protocol used is RTSP. I keep getting this error:
04-07 19:26:32.528: E/MediaPlayer(7358): Unable to to create media player
04-07 19:26:32.536: W/VideoView(7358): Unable to open content: rtsp://v2.cache1.c.youtube.com/CiULENy73wIaHAk-BOiQ3AO9gBMYDSANFEgGUglwbGF5bGlzdHMM/0/0/0/video.3gp
04-07 19:26:32.536: W/VideoView(7358): java.io.IOException: setDataSource failed.: status=0x80000000
The stream is working and the codec should be supported. Can't locate the problem. I've tried it on a Sony GTV box and on a ICS tablet.
This is the code I'm using:
videoview.setVideoURI(Uri.parse(viduri));
MediaController mc = new MediaController(PlayerActivity.this);
videoview.setMediaController(mc);
videoview.requestFocus();
videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
progressBar.setVisibility(View.GONE);
videoview.start();
}
});
Does anyone have experience with the same issue? Any solutions? The error message isn't very helpful...
What I see is that this stream can't be found. Are you obtaining this Youtube video using YouTube Data API?

video stream from vlc to android, video missing

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();
}

Categories

Resources