Skip to content

Commit

Permalink
add feature:control nav icon visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
tom committed Nov 3, 2015
1 parent 5814281 commit ed9f005
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
import android.view.View;
import android.widget.EditText;

import tcking.github.com.giraffeplayer.GiraffePlayer;
import tcking.github.com.giraffeplayer.GiraffePlayerActivity;
import tcking.github.com.giraffeplayer.GiraffeVideoPlayer;

public class MainActivity extends AppCompatActivity {
GiraffeVideoPlayer player;
GiraffePlayer player;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
player = new GiraffeVideoPlayer(this);
player = new GiraffePlayer(this);
View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -34,12 +34,13 @@ public void onClick(View v) {
((EditText) findViewById(R.id.et_url)).setText(url);
player.play(url);
player.setTitle(url);
player.setShowNavIcon(false);
}else if (v.getId() == R.id.btn_open) {
String url = ((EditText) findViewById(R.id.et_url)).getText().toString();
GiraffePlayerActivity.configPlayer(MainActivity.this).setTitle(url).play(url);
// more configuration example:
// GiraffePlayerActivity.configPlayer(MainActivity.this)
// .setScaleType(GiraffeVideoPlayer.SCALETYPE_FITPARENT)
// .setScaleType(GiraffePlayer.SCALETYPE_FITPARENT)
// .setDefaultRetryTime(5 * 1000)
// .setFullScreenOnly(false)
// .setTitle(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/**
* Created by tcking on 15/10/27.
*/
public class GiraffeVideoPlayer {
public class GiraffePlayer {
/**
* 可能会剪裁,保持原视频的大小,显示在中心,当原视频的大小超过view的大小超过部分裁剪处理
*/
Expand Down Expand Up @@ -260,7 +260,7 @@ public void handleMessage(Message msg) {
}
};

public GiraffeVideoPlayer(final Activity activity) {
public GiraffePlayer(final Activity activity) {
IjkMediaPlayer.loadLibrariesOnce(null);
IjkMediaPlayer.native_profileBegin("libijkplayer.so");
this.activity=activity;
Expand Down Expand Up @@ -745,6 +745,14 @@ public void setScaleType(String scaleType) {
}
}

/**
* 是否显示左上导航图标(一般有actionbar or appToolbar时需要隐藏)
* @param show
*/
public void setShowNavIcon(boolean show) {
$.id(R.id.app_video_finish).visibility(show ? View.VISIBLE : View.GONE);
}


class Query {
private final Activity activity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tcking.github.com.giraffeplayer;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
Expand All @@ -11,14 +10,12 @@
import android.view.Window;
import android.widget.Toast;

import java.io.Serializable;

/**
* Created by tcking on 15/10/27.
*/
public class GiraffePlayerActivity extends Activity {

GiraffeVideoPlayer player;
GiraffePlayer player;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -29,12 +26,13 @@ protected void onCreate(Bundle savedInstanceState) {
if (config == null || TextUtils.isEmpty(config.url)) {
Toast.makeText(this, "请指定播放视频的地址", Toast.LENGTH_SHORT).show();
} else {
player = new GiraffeVideoPlayer(this);
player = new GiraffePlayer(this);
player.setTitle(config.title);
player.setDefaultRetryTime(config.defaultRetryTime);
player.setFullScreenOnly(config.fullScreenOnly);
player.setScaleType(TextUtils.isEmpty(config.scaleType) ? GiraffeVideoPlayer.SCALETYPE_FITPARENT : config.scaleType);
player.setScaleType(TextUtils.isEmpty(config.scaleType) ? GiraffePlayer.SCALETYPE_FITPARENT : config.scaleType);
player.setTitle(TextUtils.isEmpty(config.title) ? "" : config.title);
player.setShowNavIcon(config.showNavIcon);
player.play(config.url);
}
}
Expand Down Expand Up @@ -98,6 +96,8 @@ public static class Config implements Parcelable {
private long defaultRetryTime = 5 * 1000;
private String title;
private String url;
private boolean showNavIcon=true;




Expand Down Expand Up @@ -139,6 +139,7 @@ private Config(Parcel in) {
defaultRetryTime = in.readLong();
title = in.readString();
url = in.readString();
showNavIcon = in.readByte() != 0;
}

@Override
Expand All @@ -153,6 +154,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(defaultRetryTime);
dest.writeString(title);
dest.writeString(url);
dest.writeByte((byte) (showNavIcon ? 1 : 0));
}

public static final Parcelable.Creator<Config> CREATOR = new Parcelable.Creator<Config>() {
Expand Down

0 comments on commit ed9f005

Please sign in to comment.