selvinEduardo / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

how to rotate video with javacv on android #500

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I write small program on android for play video, use surface. 

preview layout

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <Button
            android:id="@+id/playvideoplayer"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="- PLAY Video -"/>
        <Button
            android:id="@+id/pausevideoplayer"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="- PAUSE Video -"/>

        <SurfaceView
            android:id="@+id/surfaceview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
           />
    </LinearLayout>

preview activity code

    package preview_pack;

    import java.io.IOException;
    import android.app.Activity;
    import android.graphics.PixelFormat;
    import android.media.MediaPlayer;
    import android.net.Uri;
    import android.os.Bundle;
    import android.view.SurfaceHolder;
    import android.view.SurfaceView;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;
    import android.media.AudioManager;

    public class PlayerActivity extends Activity 
        implements SurfaceHolder.Callback {

        Uri targetUri;

        MediaPlayer mediaPlayer;
        SurfaceView surfaceView;
        SurfaceHolder surfaceHolder;
        boolean pausing = false;;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.video_preview);

            targetUri = this.getIntent().getData();

            Button buttonPlayVideo = (Button)findViewById(R.id.playvideoplayer);
            Button buttonPauseVideo = (Button)findViewById(R.id.pausevideoplayer);

            getWindow().setFormat(PixelFormat.UNKNOWN);
            surfaceView = (SurfaceView)findViewById(R.id.surfaceview);
            surfaceHolder = surfaceView.getHolder();

            surfaceHolder.addCallback(this);
            surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
            mediaPlayer = new MediaPlayer();

            buttonPlayVideo.setOnClickListener(new Button.OnClickListener(){

                @Override
                public void onClick(View arg0) {
                    pausing = false;

                     if(mediaPlayer.isPlaying()){
                         mediaPlayer.reset();    
                     }

                     mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                     mediaPlayer.setDisplay(surfaceHolder);

                     try {
                         mediaPlayer.setDataSource(getApplicationContext(), targetUri);

                         mediaPlayer.prepare();  
                     } catch (IllegalArgumentException e) {
                         e.printStackTrace();
                     } catch (IllegalStateException e) {
                         e.printStackTrace();
                     } catch (IOException e) {
                         e.printStackTrace();
                     }

                     mediaPlayer.start();

                }});

            buttonPauseVideo.setOnClickListener(new Button.OnClickListener(){

                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    if(pausing){
                        pausing = false;
                        mediaPlayer.start();    
                    }
                    else{
                        pausing = true;
                        mediaPlayer.pause();    
                    }
                }});
        }

        @Override
        protected void onDestroy() {
            // TODO Auto-generated method stub
            super.onDestroy();
            mediaPlayer.release();
        }

        @Override
        public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
            // TODO Auto-generated method stub

        }

        @Override
        public void surfaceCreated(SurfaceHolder arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void surfaceDestroyed(SurfaceHolder arg0) {
            // TODO Auto-generated method stub

        }

    }

and where I try to play video with 90 degrees on the screen I see
http://i.stack.imgur.com/hxHKP.png

When I use `surfaceView.setRotation(90)`; my surface rotates but on the screen 
only black surface and end.

Original issue reported on code.google.com by vvva...@gmail.com on 2 Mar 2015 at 6:33

GoogleCodeExporter commented 9 years ago
I'm guessing this is a duplicate of this one:
https://github.com/bytedeco/javacv/issues/98#issuecomment-76715277

Next time, please ask your questions on GitHub or the mailing list. This site 
is no longer maintained, so nobody comes and check these pages.

Original comment by samuel.a...@gmail.com on 3 Mar 2015 at 12:41