Ported media control buttons to landscape video player

This commit is contained in:
daniel oeh 2012-06-27 21:39:42 +02:00
parent 3931244c35
commit b291d56fbb
2 changed files with 113 additions and 74 deletions

View File

@ -3,49 +3,93 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" > android:orientation="vertical" >
<VideoView <VideoView
android:id="@+id/videoview" android:id="@+id/videoview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent" />
/> <!-- Mediaplayer controls -->
<!-- Mediaplayer controls -->
<RelativeLayout <LinearLayout
android:id="@+id/playercontrols" android:id="@+id/overlay"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="bottom|center"
android:background="@color/gray" >
<TextView
android:id="@+id/txtvPosition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:textColor="@color/white"
android:text="@string/position_default_label" />
<TextView
android:id="@+id/txtvLength"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="@string/position_default_label"
android:textColor="@color/white" />
<SeekBar
android:id="@+id/sbPosition"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="0px" android:layout_gravity="bottom|center"
android:layout_toLeftOf="@id/txtvLength" android:alpha="0"
android:layout_toRightOf="@id/txtvPosition" android:background="@color/white"
android:layout_alignParentBottom="true" android:orientation="vertical" >
android:max="500" />
<RelativeLayout
</RelativeLayout> android:id="@+id/playercontrol"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="clip_horizontal"
android:layout_margin="4dp" >
<ImageButton
android:id="@+id/butPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/borderless_button"
android:src="@android:drawable/ic_media_pause" />
<ImageButton
android:id="@+id/butFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="8dp"
android:layout_toRightOf="@+id/butPlay"
android:background="@drawable/borderless_button"
android:src="@android:drawable/ic_media_ff" />
<ImageButton
android:id="@+id/butRev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="8dp"
android:layout_toLeftOf="@+id/butPlay"
android:background="@drawable/borderless_button"
android:src="@android:drawable/ic_media_rew" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/timecontrol"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginBottom="4dp" >
<TextView
android:id="@+id/txtvPosition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/position_default_label" />
<TextView
android:id="@+id/txtvLength"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:text="@string/position_default_label" />
<SeekBar
android:id="@+id/sbPosition"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_toLeftOf="@+id/txtvLength"
android:layout_toRightOf="@+id/txtvPosition"
android:max="500" />
</RelativeLayout>
</LinearLayout>
</FrameLayout> </FrameLayout>

View File

@ -116,7 +116,7 @@ public class MediaplayerActivity extends SherlockActivity implements
setContentView(R.layout.mediaplayer_activity); setContentView(R.layout.mediaplayer_activity);
} }
setupGUI(); setupGUI();
} }
@Override @Override
@ -187,17 +187,13 @@ public class MediaplayerActivity extends SherlockActivity implements
positionObserver.cancel(true); positionObserver.cancel(true);
positionObserver = null; positionObserver = null;
} }
if (orientation == Configuration.ORIENTATION_PORTRAIT) { butPlay.setImageResource(android.R.drawable.ic_media_play);
butPlay.setImageResource(android.R.drawable.ic_media_play);
}
break; break;
case PLAYING: case PLAYING:
setStatusMsg(R.string.player_playing_msg, View.INVISIBLE); setStatusMsg(R.string.player_playing_msg, View.INVISIBLE);
loadMediaInfo(); loadMediaInfo();
setupPositionObserver(); setupPositionObserver();
if (orientation == Configuration.ORIENTATION_PORTRAIT) { butPlay.setImageResource(android.R.drawable.ic_media_pause);
butPlay.setImageResource(android.R.drawable.ic_media_pause);
}
break; break;
case PREPARING: case PREPARING:
setStatusMsg(R.string.player_preparing_msg, View.VISIBLE); setStatusMsg(R.string.player_preparing_msg, View.VISIBLE);
@ -209,9 +205,7 @@ public class MediaplayerActivity extends SherlockActivity implements
case PREPARED: case PREPARED:
loadMediaInfo(); loadMediaInfo();
setStatusMsg(R.string.player_ready_msg, View.VISIBLE); setStatusMsg(R.string.player_ready_msg, View.VISIBLE);
if (orientation == Configuration.ORIENTATION_PORTRAIT) { butPlay.setImageResource(android.R.drawable.ic_media_play);
butPlay.setImageResource(android.R.drawable.ic_media_play);
}
break; break;
case SEEKING: case SEEKING:
setStatusMsg(R.string.player_seeking_msg, View.VISIBLE); setStatusMsg(R.string.player_seeking_msg, View.VISIBLE);
@ -289,6 +283,9 @@ public class MediaplayerActivity extends SherlockActivity implements
sbPosition = (SeekBar) findViewById(R.id.sbPosition); sbPosition = (SeekBar) findViewById(R.id.sbPosition);
txtvPosition = (TextView) findViewById(R.id.txtvPosition); txtvPosition = (TextView) findViewById(R.id.txtvPosition);
txtvLength = (TextView) findViewById(R.id.txtvLength); txtvLength = (TextView) findViewById(R.id.txtvLength);
butPlay = (ImageButton) findViewById(R.id.butPlay);
butRev = (ImageButton) findViewById(R.id.butRev);
butFF = (ImageButton) findViewById(R.id.butFF);
sbPosition.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { sbPosition.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
int duration; int duration;
@ -322,34 +319,32 @@ public class MediaplayerActivity extends SherlockActivity implements
} }
}); });
butPlay.setOnClickListener(playbuttonListener);
butFF.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (status == PlayerStatus.PLAYING) {
playbackService.seekDelta(DEFAULT_SEEK_DELTA);
}
}
});
butRev.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (status == PlayerStatus.PLAYING) {
playbackService.seekDelta(-DEFAULT_SEEK_DELTA);
}
}
});
if (orientation == Configuration.ORIENTATION_PORTRAIT) { if (orientation == Configuration.ORIENTATION_PORTRAIT) {
imgvCover = (ImageView) findViewById(R.id.imgvCover); imgvCover = (ImageView) findViewById(R.id.imgvCover);
txtvStatus = (TextView) findViewById(R.id.txtvStatus); txtvStatus = (TextView) findViewById(R.id.txtvStatus);
butPlay = (ImageButton) findViewById(R.id.butPlay);
butRev = (ImageButton) findViewById(R.id.butRev);
butFF = (ImageButton) findViewById(R.id.butFF);
txtvTitle = (TextView) findViewById(R.id.txtvTitle); txtvTitle = (TextView) findViewById(R.id.txtvTitle);
txtvFeed = (TextView) findViewById(R.id.txtvFeed); txtvFeed = (TextView) findViewById(R.id.txtvFeed);
butPlay.setOnClickListener(playbuttonListener);
butFF.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (status == PlayerStatus.PLAYING) {
playbackService.seekDelta(DEFAULT_SEEK_DELTA);
}
}
});
butRev.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (status == PlayerStatus.PLAYING) {
playbackService.seekDelta(-DEFAULT_SEEK_DELTA);
}
}
});
} else { } else {
setTheme(R.style.Theme_Sherlock_Light_NoActionBar); setTheme(R.style.Theme_Sherlock_Light_NoActionBar);
videoview = (VideoView) findViewById(R.id.videoview); videoview = (VideoView) findViewById(R.id.videoview);