2

I have googled a lot and found no success at all.Not even single point from which I can kickstart. I am using VideoView to play the video from url, successfully it's playing the video, at the same time I want to record the currently playing video. e.g: http://ip/streamname/playlist.m3u8 is the url and I watch it successfully, but I need to record the particular stream and save it so that I can watch it later. Please suggest me the solution

Rahul Matte
  • 1,151
  • 2
  • 23
  • 54
  • have you tried MediaRecorder Api for recording video?? this also give us facitlity to record video by setting video source. – yasiriqbal776 Jul 04 '14 at 08:25
  • I tried but not working...ok I will try once again. But I have doubt can I set video source as a url which is of currently playing video – Rahul Matte Jul 04 '14 at 08:29

1 Answers1

2

Try this code to download your video from your url and one thing remember server must support downloading from a specific byte offset

        private final int TIMEOUT_CONNECTION = 5000;//5sec
        private final int TIMEOUT_SOCKET = 30000;//30sec
        URL url = new URL("Video URL");
      //  long startTime = System.currentTimeMillis();
       // Log.i(TAG, "image download beginning: "+imageURL);

        //Open a connection to that URL.
        URLConnection ucon = url.openConnection();

        //this timeout affects how long it takes for the app to realize there's a //connection problem
        ucon.setReadTimeout(TIMEOUT_CONNECTION);
        ucon.setConnectTimeout(TIMEOUT_SOCKET);


        //Define InputStreams to read from the URLConnection.
        // uses 3KB download buffer
        InputStream is = ucon.getInputStream();
        BufferedInputStream inStream = new BufferedInputStream(is, 1024 * 5);
        FileOutputStream outStream = new FileOutputStream(file);
        byte[] buff = new byte[5 * 1024];

        //Read bytes (and store them) until there is nothing more to read(-1)
        int len;
        while ((len = inStream.read(buff)) != -1)
        {
            outStream.write(buff,0,len);
        }

        //clean up
        outStream.flush();
        outStream.close();
        inStream.close();

        Log.i(TAG, "download completed in "
                + ((System.currentTimeMillis() - startTime) / 1000)
                + " sec");5
yasiriqbal776
  • 406
  • 3
  • 15
  • it's downloading the file but when I checked the properties of the file it was 0 bytes when I click on that file player startis playing it. But I observed that the file is again same stream url – Rahul Matte Jul 09 '14 at 14:41
  • did your server support downloading?? – yasiriqbal776 Jul 09 '14 at 15:10
  • i dont think wowzo is giving downloading support although wowzo is giving nDVR module so that end user can fast forward or fast rewind or play/pause the videos. – yasiriqbal776 Jul 09 '14 at 16:11
  • Thank you @yasiriqbal776 . How can I specify the seconds into the video? For example, lets say I want to save only 5 seconds in the middle of the video? – code Mar 06 '15 at 02:24
  • @android-user i didn't understand your question? do you want to get time of video? – yasiriqbal776 Mar 06 '15 at 09:33
  • Hi @yasiriqbal776 , for example given www.test.com/video.mp4 , I would like to be able to download a 10 second clip in the middle of the video (example: 00:01:05 to 00:01:15). Is it possible to save this time range? How could I get the byte range based on the desired seconds? – code Mar 06 '15 at 09:37
  • which server are you using? you should implement in your web service which get offset and return byte array. and then you can play that byte array in mediaplayer object in android – yasiriqbal776 Mar 06 '15 at 11:01