Android video stream from url over the videoview or surfaceview - android

There are so many posts on the same topic but no one is giving proper reason for this error, Could some one help me to solving this error.
My code is working fine for SDCARD videos. whenever I try to access it from url it throws this error.
W/MediaPlayer: Couldn't open file on client side; trying server side: java.io.FileNotFoundException: No content provider: http://download.itcuties.com/teaser/itcuties-teaser-480.mp4
E/MediaPlayer: error (1, -2147483648)
I tried several formats and several urls for everything i am getting the same error.
Internet permissions given.
Code:
public class MainActivity extends AppCompatActivity {
VideoView video1;
String url ="http://download.itcuties.com/teaser/itcuties-teaser-480.mp4";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
video1 = (VideoView) findViewById(R.id.video1);
video1.setVideoURI(Uri.parse(url));
video1.setMediaController(new MediaController(this));
video1.requestFocus();
Thread view1=new Thread(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_DISPLAY);
video1.start();
}
});
}
}

You just need to start your view1 thread. Your code loads the video but doesn't play it. Adding this will solve the issue.
view1.start();

Related

"Can't play this video" Error using URL with VideoView and Mediacontroller

So I'm trying to do my homework, but the teacher's given me 0 information about this. There is an example of how to play a video from a file in the res/raw folder, but there's nothing about online URLs. Please help me, I just want a simple player. I'll attach a picture detailing exactly what is up. I'll also add the code, since it's not that much and I really have no clue what could be wrong. Error says this:
W/MediaPlayer: Couldn't open http://techslides.com/...
java.io.FileNotFoundException: No content provider: http://techslides.com/demos/sample-videos/small.mp4
And this is the code:
VideoView video;
String url = "http://techslides.com/demos/sample-videos/small.mp4";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
video = (VideoView) findViewById(R.id.videoView);
MediaController mc = new MediaController(this);
mc.setAnchorView(mc);
video.setVideoPath(url);
video.setMediaController(mc);
video.start();
}
I will finally add to this that I've tried several different URLs, including some https ones and some http.
EDIT:
So, I tried fixing it and it ended up looking like this:
video = (VideoView) findViewById(R.id.videoView);
final MediaController mc = new MediaController(this);
mc.setAnchorView(mc);
video.setVideoPath(url);
video.setMediaController(mc);
video.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
#Override
public void onPrepared(MediaPlayer mp){
video.start();
}
});
But it still gives me the same error when the emu is open. "Can't play this video". On the other hand, I got a bunch of new errors:
E/MediaPlayerNative: error (1, -2147483648)
E/MediaPlayer: Error (1,-2147483648)
D/VideoView: Error: 1,-2147483648
I'm not really familiarized with this technology, and the teacher hasn't given us any notions whatsoever as to what should or shouldn't be in the code for it to work. Just an example of a locally stored video playing in Android Studio with VideoView... that doesn't work when applied to online URLs.
So I've ended up fixing it myself. The problem wasn't in the code, for anyone wondering I've ended up using this simple format:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
video = (VideoView) findViewById(R.id.video);
Uri uri = Uri.parse("http://techslides.com/demos/sample-videos/small.mp4");
video.setMediaController(new MediaController(this));
video.setVideoURI(uri);
video.requestFocus();
video.start();
}
The problem was the AVD itself. I had a Pixel 1 running Android 9, and that for some reason didn't work. I've installed a Nexus 5 with Oreo and it works flawlessly.
This may help you
VideoView simpleVideoView = (VideoView) findViewById(R.id.simpleVideoView); // initiate a video view
// perform set on prepared listener event on video view
simpleVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
// do something when video is ready to play, you want to start playing video here
}
});
Try to start video only when its fully ready to play. Since mp4 will take some time to download.. so it might be in inconsistent state when you started video.
Hope this will help.

Firebase video to videoview not working

I am able to record and able to upload that video to firebase from my android app but not being able to play or stream(whatever is possible) to videoview. I am actually trying to get in it the recycler view but since it didn't work trying something simpler.
I read many post here in stackoverflow and tried almost all of them but none worked.So posting new question.
My code are as follows:
VideoView video;
//String video_url = "http://file2.video9.in/english/movie/2014/x-men-_days_of_future_past/X-Men-%20Days%20of%20Future%20Past%20Trailer%20-%20[Webmusic.IN].3gp";//this one works if i use it
String video_url = "https://firebasestorage.googleapis.com/longidcharacters-video.mp4?alt=media&token=xxxxx";
//but this link from firebase does not work, i usually fetch it from online
ProgressDialog pd;
Button playButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_video);
video = (VideoView) findViewById(R.id.Videoview1);
playButton=(Button) findViewById(R.id.playButton1);
pd = new ProgressDialog(ShowVideoActivity.this);
pd.setMessage("Buffering video please wait...");
pd.show();
Uri uri = Uri.parse(video_url);
video.setVideoURI(uri);
video.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
//close the progress dialog when buffering is done
pd.dismiss();
}
});
playButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
video.start();
}
});
It says "cannot play this video". The format is mp4(recorded from camera). However, if I play that 3gp one(which is commented now),it works fine.
What can i do? Is there any player I can try? I am just trying to stream or play video that is uploaded to firebase storage.

Android VideoView not detecting streaming error

Whenever videoview is playing a video and there is a network connection drop and the video freezes, my code is not throwing an error even though I have set the videoview error listener.
public class MainActivity extends Activity {
static MediaController mc;
static VideoView vw;
/** Called when the activity is first created. */
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
mc = new MediaController(this);
vw = (VideoView) findViewById(R.id.videoView);
vw.setVideoPath("http://173.45.164.105:1935/live/myStream/playlist.m3u8");
vw.setOnErrorListener(new MediaPlayer.OnErrorListener() {
#Override
public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
vw.stopPlayback();
vw.start();
Log.i("VIDEO ERROR ", "FROZE");
return true;
}
});
vw.requestFocus();
vw.start();
}
}
To my understanding the native VideoView element only calls the onError() method when opening the video.
See: VideoView Source
In the openVideo() method -- called when setting the VideoView path/URI -- a couple of exceptions are handled by throwing a MediaPlayer.MEDIA_ERROR_UNKNOWN error.
I'm not positive what goes on in the background with the MediaPlayer whenever a connection is lost with the video source, but it seems that it simply waits indefinitely waiting to re-establish a connection. It will never throw an error via the onErrorListener.
However if you call the setVideoPath() or setVideoUri() method again it will call the onError() method b/c an Exception will be thrown in openVideo().
You'll have to either figure out some way to detect that the connection is lost or wait to see if the time on the video is getting updated and throw an error manually.
If anyone finds a better way to fix this let me know.

RTSP streaming in android

Here is my code, and when I run the app, it will display "Sorry this video cannot be played".
public class rtspActivity extends Activity {
Button btn;
VideoView v;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rtsp);
v=(VideoView)findViewById(R.id.vv);
v.setVideoURI(Uri.parse("rtsp://server.intelcast.tv:554/live/haditvfour1"));
}
}
You should start with
v.setMediaController(new MediaController(this));
v.requestFocus();
v.start();
Also, the url you're using might not be good. Try it in VLC or similar, to see if its actually there
Another problem can be the "server.intelcast.tv:554" part, try replacing this with a real ip adress with numbers, i've experinced this issue myself

Facing problem in Android Video streaming

I created a simple application which will stream video from an URL, it works fine when i point to some local URL like,
http://192.168.X.XX:XXX/Tutorial/TestVideo.mp4
But when try to point some external URL like,
http://122.183.X.XX/Tutorial/TestVideo.mp4
the app is not working. In both the URLs i am having the same video file. When i work with the external URL i am getting the following logcat info
08-17 17:34:28.772: INFO/Prefetcher(34): max duration reached, size = 960201 bytes
Please find my code below:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
preview=(VideoView)findViewById(R.id.surface);
preview.setEnabled(true);
preview.bringToFront();
MediaController mc=new MediaController(playerActivity.this);
mc.setMediaPlayer(player_interface);
mc.show(50);
preview.setMediaController(mc );
holder=preview.getHolder();
holder.setFixedSize(400, 400);
b=(Button)findViewById(R.id.cmd_play);
pb=(ProgressBar)findViewById(R.id.progress);
b.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
try
{
mp.setDisplay(holder);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setOnBufferingUpdateListener(playerActivity.this);
mp.setOnPreparedListener(playerActivity.this);
mp.prepare();
mp.start();
mp.seekTo(20000);
}
catch(Exception e)
{
}
}
I don't know what is the problem, please some body help me if you know the solution for this.
Thanks and Regards,
Rajapandian
If this is occurring on the emulator try this solution and try it on an actual phone. If this isn't the problem, you'll need to post the code you are using to load the video.

Categories

Resources