2017-09-01 127 views
1

沒有Main2Activity的情況下一切正常,但我想要做的是在單擊全屏按鈕時播放Main2Activity上的視頻。在MainActivity上一切正常,但是當我點擊全屏按鈕時,它會崩潰。不知道爲什麼。我是Android開發新手,任何幫助將不勝感激。用全屏按鈕在下一個活動上播放視頻

MainActivity:

public class MainActivity extends AppCompatActivity { 


    Button buttonPlay; 
    Button buttonFullScreen; 
    static final int REQUEST_VIDEO_CAPTURE = 1; 
    VideoView resultvideo; 
    MediaController mediacontroller; 

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

     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     this.setContentView(R.layout.activity_main); 

     setContentView(R.layout.activity_main); 

     resultvideo = (VideoView)findViewById(R.id.videoView); 
     mediacontroller = new MediaController(MainActivity.this); 

     mediacontroller.setAnchorView(resultvideo); 

     resultvideo.setMediaController(mediacontroller); 

     Button click = (Button)findViewById(R.id.buttonRecord); 
     resultvideo = (VideoView)findViewById(R.id.videoView); 
    } 

    public void dispatchTakeVideoIntent(View v) { 
     Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); 
     if (takeVideoIntent.resolveActivity(getPackageManager()) != null) { 
      startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE); 
     } 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) { 
      Uri videoUri = data.getData(); 
      Log.i("test","111111111111111" + videoUri.toString()); 
      resultvideo.setVideoURI(videoUri); 
      mediacontroller.setAnchorView(resultvideo); 
      resultvideo.pause(); 

     } 
     buttonPlay = (Button) findViewById(R.id.buttonPlay); 
     { 
      buttonPlay.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        mediacontroller.show(); 
        mediacontroller.setAnchorView(resultvideo); 
        resultvideo.start(); 
        Log.i("test","111111111111111"); 
       } 
      }); 
     } 

     buttonFullScreen = (Button) findViewById(R.id.buttonFullScreen); 
     { 
      buttonFullScreen.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        startActivity(new Intent(MainActivity.this, Main2Activity.class)); 
       } 
      }); 
     } 
    } 
} 

Main2Activity:

public class Main2Activity extends MainActivity { 

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

     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 

     setContentView(R.layout.activity_main2); 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data){ 
     if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) { 
      Uri videoUri = data.getData(); 
      Log.i("test", "111111111111111" + videoUri.toString()); 
      resultvideo.setVideoURI(videoUri); 
      mediacontroller.setAnchorView(resultvideo); 
      resultvideo.pause(); 

     } 
     buttonFullScreen = (Button) findViewById(R.id.buttonFullScreen); 
     { 
      buttonFullScreen.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        mediacontroller.show(); 
        mediacontroller.setAnchorView(resultvideo); 
        resultvideo.start(); 
        Log.i("test","111111111111111"); 
       } 
      }); 
     } 
    } 
} 
+0

發佈您的崩潰日誌 – Yupi

+0

發佈您的崩潰日誌,並且不要將java代碼添加爲片段! – Zoe

+0

什麼是寫在崩潰日誌? – Zoffa

回答

0

resultvideo在MainActivity聲明,它不提供Main2Activity

+0

它仍然崩潰。 – Renzo

+0

請在這裏發佈您的崩潰日誌 –

0

mediacontrollerresultvideo在MainActivity聲明,他們是在Main2Activity ?您還必須在Main2Activity的佈局中安排它們,因爲您在MainActivity佈局中找到它們,並通過Main2Activity中的ID找到它們也是必需的。