0

Here is my code. This code have to wait until Vdo is transferred then it can play

How can i modify it to play video from stream line

    videoV = (SurfaceView) findViewById(R.id.SurfaceView1);
    Log.d("Connecting.... 0 " , "");
    sh = videoV.getHolder();
    b = (Button)findViewById(R.id.button1);
    File path = Environment.getExternalStorageDirectory();
    File file = new File(path, "sample.3gp");

    Log.d("Connecting.... 1 " , " Wait For Socket");
    try {
        Log.e("Connecting.... 2" , "");
        sock = new Socket("10.4.18.43", 5550);
        Log.e("Receiving video..." , "");

        final FileOutputStream fos = new FileOutputStream(file);
        final byte[] data = new byte[1024];

        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                int count = 0;
                try {
                    count = sock.getInputStream().read(data, 0, data.length);
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                 while (count != -1) {
                    System.out.println(count);
                try {
                    fos.write(data, 0, count);
                    count = sock.getInputStream().read(data, 0, data.length);
                    Log.e("Receiving", "Receiving");
                    } catch (IOException e) {
                    e.printStackTrace();
                }

                }
                 Log.e("Receiving", "Finish");
            }
        });
        t.start();



    } catch (UnknownHostException e3) {
        // TODO Auto-generated catch block
        e3.printStackTrace();
    } catch (IOException e3) {
        // TODO Auto-generated catch block
        e3.printStackTrace();
    }


    sh.addCallback(this);     
    mp = new MediaPlayer();
    try {

        mp.setDataSource(file.getAbsolutePath());
        //mp.setDataSource(ParcelFileDescriptor.fromSocket(sock).getFileDescriptor());
        mp.setDisplay(sh);
    } catch (IllegalArgumentException e1) {
        e1.printStackTrace();
    } catch (IllegalStateException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

     b.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {


                try {
                    mp.prepare();
                    //mp.prepareAsync();
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                mp.start();
            }
        });
user829821
  • 563
  • 1
  • 6
  • 8

1 Answers1

0

Recording is possible, but you can't play streaming video directly without writing file. If you are going to play stream video directly from socket parcel file descriptor, Mediaplayer will throw a setDetaSourceFD exception because socket file fd is not seekable.

Suvam Roy
  • 1,282
  • 2
  • 11
  • 21
  • what we should do for playing stream video through parcel file descriptor? give me some ideas – Aravi Dec 10 '13 at 08:27