2

I'm trying to stream a video and play it using VideoView. I supply the view with the source URL of the video with setVideoURI() as shown below. With a hardcoded value like urlString = "www.myvideoserver.com/videos/bigbuckbunny.mp4", the video plays fine. However, when urlString is given the value from the intent (coming from the previous activity where the user chose the video), I get the message: "Sorry, Video cannot be played". I've read that one of the common causes is video format, like it's described here and here. I'm almost certain that it is not a format issue because I can play the video when the URL is fixed (and I know this because I can see from Log.d("PVurl", urlString); that the value of urlString is exactly the same as the one I fixed it to. That is, in LogCat, I copy paste the value into the line urlString = getIntent()... // "www.myvideoserver.com/videos/bigbuckbunny.mp4", and it works but not when urlString is set to the intent return value . LogCat Errror panel gives the following:

04-13 17:35:32.786: ERROR/MediaPlayer(2620): error (1, -1007)
04-13 17:35:32.786: ERROR/MediaPlayer(2620): Error (1,-1007)

I've searched around the internet but it doesn't seem that anyone has encountered such an error code before.

I'd very much appreciate if anyone has any idea what could be the problem. Thanks!

public void playvideo () { // obtain URL of the requested video from the intent in previous activity

    try
    {
        urlString =  getIntent().getStringExtra("mypackage.fulladdr");

        if (urlStr != null)
        {
            Log.d("PVurl", urlString);

            VideoView v = (VideoView) findViewById(R.id.videoView1);

            // play video

            v.setVideoURI(Uri.parse(urlString));
            v.setMediaController(new MediaController(this));
            v.start();

            v.setOnCompletionListener(new OnCompletionListener() {
                public void onCompletion(MediaPlayer mp) {
                    showRatingDialog();
                }
            });
        }
    }
    catch (Exception e)
    {
        Log.d("PV_TAG", +e.getMessage());
        e.printStackTrace();
    }
}
Community
  • 1
  • 1
kip2
  • 6,473
  • 4
  • 55
  • 72

4 Answers4

1

You haven't added the scheme which the Uri needs to find out what it is referring to (http, in your case) .

urlString = "www.myvideoserver.com/videos/bigbuckbunny.mp4" change it to urlString = "http://www.myvideoserver.com/videos/bigbuckbunny.mp4"

Akhil
  • 13,888
  • 7
  • 35
  • 39
  • thanks. But the actual url is indeed "http://www.myvideoserver.com/videos/bigbuckbunny.mp4", I'm sorry for not including the 'http' part in my earlier question. Like I said, the problem is that when urlString is hardcoded to the above value (or any other valid source URL for that matter), the video player works as usual. However, when it is set to a variable from another activity, the player fails with the error message (1, -1007). So I'm not really sure what's going on... – kip2 Apr 16 '12 at 17:08
  • thanks. but again, both the hardcoded URL and the variable-assigned URL (urlString) have 'http' in them. The situation is like this: say you have a variable called 'x': and say you need to assign y as follows: y = sqrt(x); if x is assigned an actual value like x =25, it works. but not when x = [output of some other operation], namely, an intent in my particular case. yet I'm sure that the intent produces the correct value – kip2 Apr 16 '12 at 21:34
  • i have same url as u said but still i got problem ... please heelppp me :( – Vaishali Sutariya Aug 07 '14 at 12:34
1

(1, -1007) error means: MEDIA_ERROR_UNKNOWN - "File or network related operation errors."

this may come from a corrupt file

see also javadoc of android.media.MediaPlayer.OnErrorListener#onError http://developer.android.com/reference/android/media/MediaPlayer.OnErrorListener.html#onError

@param what the type of error that has occurred:
MEDIA_ERROR_UNKNOWN
MEDIA_ERROR_SERVER_DIED

@param extra an extra code, specific to the error. Typically implementation dependent.
MEDIA_ERROR_IO
MEDIA_ERROR_MALFORMED
MEDIA_ERROR_UNSUPPORTED
MEDIA_ERROR_TIMED_OUT
electrobabe
  • 1,549
  • 18
  • 17
0

I tried the same thing and was able to get it to work. Perhaps something else is going on in your code. Here is what I have:

// Intent to start the activity that launches the video player
Intent i = new Intent(this, ExampleActivity.class);
i.putExtra("url", "http://www.yourvideo.com/yourvid.m4v");
startActivity(i);

And here is the code that deals with the player:

private MediaController mController;
private Uri videoUri; 
private int percentBuffered= 0;
private VideoView videoView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.your_layout);

    mController = new MediaController(this);

    videoView = (VideoView) findViewById(R.id.videoView1);

    // access String from the intent that launched this Activity
    videoUri = Uri.parse(getIntent().getStringExtra("url"));
}

@Override
public void onResume() {
    super.onResume();
    videoView.setOnCompletionListener(this);
    try {
        videoView.setVideoURI(videoUri);
        mController.setMediaPlayer(videoView);
        videoView.setMediaController(mController);
        videoView.requestFocus();
        videoView.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

@Override
protected void onPause() {
    super.onPause();
    finish();
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    mController.show();
    return super.onTouchEvent(event);
}

@Override
public int getBufferPercentage() {
    return percentBuffered;
}

@Override
public int getCurrentPosition() { 
    return videoView.getCurrentPosition();
}

@Override
public int getDuration() {
    return videoView.getDuration();
}

@Override
public boolean isPlaying() {
    return videoView.isPlaying();
}

@Override
public void pause() {
    videoView.pause();
}

@Override
public void seekTo(int pos) {
    videoView.seekTo(pos);
}

@Override
public void start() {
    videoView.start();
}

@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
    percentBuffered = percent;
}

@Override
public void onCompletion(MediaPlayer mp) {

}

public boolean canPause() {
    return true;
}

public boolean canSeekBackward() {
    return true;
}

public boolean canSeekForward() {
    return true;
}
Swifty McSwifterton
  • 2,637
  • 1
  • 30
  • 37
  • thanks for sharing. I've modified my code to look like yours but it still has the same issue. The error code given by the setOnErrorListener is (1, -1007) – kip2 Apr 16 '12 at 17:09
0

Alright, I found the problem after many futile hours of digging through to find what MediaPlayer error(1, -1007) means.

In reality, it has to do with the rather unfortunate fact that the line getIntent().getStringExtra("mypackage.fulladdr"); returns a string with an extra white space at the end. I think it's an implementation issue with getIntent(). Anyone knows where to report these kind of bugs, that'd be great.

Thanks to @Akhil and @javaMe for their attempts!

kip2
  • 6,473
  • 4
  • 55
  • 72