Skip to content

Commit

Permalink
1.support https
Browse files Browse the repository at this point in the history
2.support x86
3.add some api
  • Loading branch information
tom committed Feb 17, 2016
1 parent 757db9e commit 34ad09c
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
versionName "1.0"

ndk {
abiFilters "armeabi-v7a"
abiFilters "armeabi-v7a","x86"
}
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,22 @@ public void onClick(View v) {
// .setFullScreenOnly(false)
// .setTitle(url)
// .play(url);
}else if (v.getId() == R.id.btn_start) {
player.start();
}else if (v.getId() == R.id.btn_pause) {
player.pause();
}else if (v.getId() == R.id.btn_toggle) {
player.toggleFullScreen();
}
}
};
findViewById(R.id.btn_play).setOnClickListener(clickListener);
findViewById(R.id.btn_play_sample_1).setOnClickListener(clickListener);
findViewById(R.id.btn_play_sample_2).setOnClickListener(clickListener);
findViewById(R.id.btn_play_sample_3).setOnClickListener(clickListener);
findViewById(R.id.btn_pause).setOnClickListener(clickListener);
findViewById(R.id.btn_start).setOnClickListener(clickListener);
findViewById(R.id.btn_toggle).setOnClickListener(clickListener);
findViewById(R.id.btn_open).setOnClickListener(clickListener);
}

Expand Down Expand Up @@ -91,4 +101,12 @@ public void onConfigurationChanged(Configuration newConfig) {
player.onConfigurationChanged(newConfig);
}
}

@Override
public void onBackPressed() {
if (player != null && player.onBackPressed()) {
return;
}
super.onBackPressed();
}
}
21 changes: 21 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@
/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/btn_pause"
android:text="pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/btn_start"
android:text="start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/btn_toggle"
android:text="toggleFullScreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</LinearLayout>

<Button
android:id="@+id/btn_play_sample_1"
android:text="play sample 1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class GiraffePlayer {
private final SeekBar seekBar;
private final AudioManager audioManager;
private final int mMaxVolume;
private boolean playerSupport;
private String url;
private Query $;
private int STATUS_ERROR=-1;
Expand All @@ -83,16 +84,13 @@ public class GiraffePlayer {
private int defaultTimeout=3000;
private int screenWidthPixels;



private final View.OnClickListener onClickListener=new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v.getId() == R.id.app_video_fullscreen) {
if (getScreenOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
updateFullScreenButton();
toggleFullScreen();
} else if (v.getId() == R.id.app_video_play) {
doPauseResume();
show(defaultTimeout);
Expand Down Expand Up @@ -261,8 +259,13 @@ public void handleMessage(Message msg) {
};

public GiraffePlayer(final Activity activity) {
IjkMediaPlayer.loadLibrariesOnce(null);
IjkMediaPlayer.native_profileBegin("libijkplayer.so");
try {
IjkMediaPlayer.loadLibrariesOnce(null);
IjkMediaPlayer.native_profileBegin("libijkplayer.so");
playerSupport=true;
} catch (Throwable e) {
Log.e("GiraffePlayer", "loadLibraries error", e);
}
this.activity=activity;
screenWidthPixels = activity.getResources().getDisplayMetrics().widthPixels;
$=new Query(activity);
Expand Down Expand Up @@ -366,6 +369,9 @@ public void onOrientationChanged(int orientation) {
portrait=getScreenOrientation()==ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
initHeight=activity.findViewById(R.id.app_video_box).getLayoutParams().height;
hideAll();
if (!playerSupport) {
showStatus(activity.getResources().getString(R.string.not_support));
}
}

/**
Expand All @@ -391,12 +397,12 @@ private void statusChange(int newStatus) {
}else if (newStatus == STATUS_ERROR) {
hideAll();
if (isLive) {
showStatus("播放出了点小问题,正在重试...");
showStatus(activity.getResources().getString(R.string.small_problem));
if (defaultRetryTime>0) {
handler.sendEmptyMessageDelayed(MESSAGE_RESTART_PLAY, defaultRetryTime);
}
} else {
showStatus("不能播放此视频");
showStatus(activity.getResources().getString(R.string.small_problem));
}
} else if(newStatus==STATUS_LOADING){
hideAll();
Expand Down Expand Up @@ -510,9 +516,11 @@ private void showStatus(String statusText) {

public void play(String url) {
this.url = url;
$.id(R.id.app_video_loading).visible();
videoView.setVideoPath(url);
videoView.start();
if (playerSupport) {
$.id(R.id.app_video_loading).visible();
videoView.setVideoPath(url);
videoView.start();
}
}

private String generateTime(long time) {
Expand Down Expand Up @@ -608,7 +616,7 @@ else if (index < 0)
int i = (int) (index * 1.0 / mMaxVolume * 100);
String s = i + "%";
if (i == 0) {
s = "关闭";
s = "off";
}
// 显示
$.id(R.id.app_video_volume_icon).image(i==0?R.drawable.ic_volume_off_white_36dp:R.drawable.ic_volume_up_white_36dp);
Expand Down Expand Up @@ -715,6 +723,8 @@ public void setFullScreenOnly(boolean fullScreenOnly) {
tryFullScreen(fullScreenOnly);
if (fullScreenOnly) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
}

Expand Down Expand Up @@ -753,6 +763,22 @@ public void setShowNavIcon(boolean show) {
$.id(R.id.app_video_finish).visibility(show ? View.VISIBLE : View.GONE);
}

public void start() {
videoView.start();
}

public void pause() {
videoView.pause();
}

public boolean onBackPressed() {
if (!fullScreenOnly && getScreenOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
return true;
}
return false;
}


class Query {
private final Activity activity;
Expand Down Expand Up @@ -920,4 +946,36 @@ public boolean onSingleTapUp(MotionEvent e) {
return true;
}
}

/**
* is player support this device
* @return
*/
public boolean isPlayerSupport() {
return playerSupport;
}

public void stopPlayback(){
videoView.stopPlayback();
}

public void seekTo(int msec){
videoView.seekTo(msec);
}

public void playInFullScreen(boolean fullScreen){
if (fullScreen) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
updateFullScreenButton();
}
}

public void toggleFullScreen(){
if (getScreenOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
updateFullScreenButton();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.Window;
import android.widget.Toast;

Expand Down Expand Up @@ -96,9 +97,7 @@ public static class Config implements Parcelable {
private long defaultRetryTime = 5 * 1000;
private String title;
private String url;
private boolean showNavIcon=true;


private boolean showNavIcon = true;


public Config setTitle(String title) {
Expand Down Expand Up @@ -167,4 +166,12 @@ public Config[] newArray(int size) {
}
};
}

@Override
public void onBackPressed() {
if (player != null && player.onBackPressed()) {
return;
}
super.onBackPressed();
}
}
4 changes: 3 additions & 1 deletion giraffeplayer/src/main/res/values-ch/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<resources>
<string name="app_name">GiraffePlayer</string>
<string name="giraffe_player_url_empty">请指定播放视频的地址</string>
<string name="small_problem">请指定播放视频的地址</string>
<string name="small_problem">发送了点小问题,稍后重试</string>
<string name="can_not_play">不能播放此视频</string>
<string name="not_support">播放器不支持此设备</string>
</resources>
1 change: 1 addition & 0 deletions giraffeplayer/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<string name="app_name">GiraffePlayer</string>
<string name="giraffe_player_url_empty">Porfavor introduce la direccion de streaming</string>
<string name="small_problem">El Player tiene una problema</string>
<string name="not_support">player not support this device</string>
</resources>
1 change: 1 addition & 0 deletions giraffeplayer/src/main/res/values-ro/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<string name="app_name">GiraffePlayer</string>
<string name="giraffe_player_url_empty">Please specify the address of the video playback</string>
<string name="small_problem">Player encountered a small problem</string>
<string name="not_support">player not support this device</string>
</resources>
2 changes: 2 additions & 0 deletions giraffeplayer/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
<string name="app_name">GiraffePlayer</string>
<string name="giraffe_player_url_empty">Please specify the address of the video playback</string>
<string name="small_problem">Player encountered a small problem</string>
<string name="can_not_play">can not play this video</string>
<string name="not_support">player not support this device</string>
</resources>
Binary file not shown.
Binary file not shown.
Binary file added ijkplayer-java/src/main/jniLibs/x86/libijksdl.so
Binary file not shown.

0 comments on commit 34ad09c

Please sign in to comment.