1

I have an Activity that uses a VideoView to play a video file. The onCreate method sets the orientation to Landscape, and then loads the video and plays it.

This video activity is called from my main activity. The main activity is set to portrait orientation in the manifest.

This all works great when the phone is held vertically. - Main Activity starts in portrait - Click button to launch video activity - Video activity launches in landscape - Video plays

However, if the phone is help horizontally, the video does not start playing: - Main Activity starts in portrait - Click button to launch video activity - Video activity launches in landscape - Video is loaded but is paused - have to manually start.

Any ideas on why this might be happening?

Video Activity Code:

protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.video_view);

    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    mVideoView = (VideoView)this.findViewById(R.id.VideoView);
    String videoUrl = "/mnt/sdcard-ext" + "/Videos/Wildlife.wmv";
    playVideo(videoUrl);

    // video finish listener
    mVideoView.setOnCompletionListener(new MyOnCompletionListener());
}

public void playVideo(String videoUrl)
{
    MediaController mc = new MediaController(this);
    mc.setAnchorView(mVideoView);
    mVideoView.setMediaController(mc);
    mVideoView.setVideoURI(Uri.parse(videoUrl));
    mVideoView.requestFocus(); 
    mVideoView.start();
}
J J
  • 1,550
  • 4
  • 17
  • 27

3 Answers3

0

Try putting log messages inside your onCreate(). Maybe in your scenario Activity is created twice.

0

I have an app that can be used in portrait or landscape that involves random info. When I switch from portrait to landscape and vice versa new info is generated. This leads me to think

onCreate()

is called even when the phone rotates. (Verification?)

I don't see why calling it twice would pause the video, but perhaps tagging your Video Activity in the manifest also, this time for landscape,

android:screenOrientation="landscape"

would prevent it from calling twice.

Cheers

jeddrp
  • 126
  • 5
  • Unfortunately, that doesn't seem to be it... Tested that OnCreate is only called once. – J J Jun 17 '11 at 01:22
0

If you want to always call it in landscape , just put this info in manifest file .It will work perfectly

Kavitha
  • 461
  • 2
  • 8
  • 22
  • add this attribute android:screenOrientation="landscape" to your activity in manifest file – Kavitha Jun 16 '11 at 22:42
  • I get the same behavior when the attribute is in the manifest as well :/ – J J Jun 17 '11 at 00:11
  • Try this http://stackoverflow.com/questions/1410504/android-how-to-make-application-completely-ignore-screen-orientation-change , you might have to override that function @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); } – Kavitha Jun 17 '11 at 22:12