Skip to content

Commit

Permalink
1、添加了TCP、UDP模式切换
Browse files Browse the repository at this point in the history
2、不支持的码流在上层提示
3、修改列表多个视频点时播放可能错位的问题
4、底层事件提示
  • Loading branch information
jiaozebo@gmail.com committed Oct 21, 2016
1 parent 881a757 commit 924bb00
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 22 deletions.
Binary file modified Android/EasyPlayer/libs/rtspclient-release.aar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
import android.preference.PreferenceManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.GestureDetectorCompat;
Expand Down Expand Up @@ -75,7 +76,7 @@ public void run() {
if (length == 0) {
mLastReceivedLength = 0;
}
if (length < mLastReceivedLength){
if (length < mLastReceivedLength) {
mLastReceivedLength = 0;
}
mBinding.liveVideoBar.streamBps.setText((length - mLastReceivedLength) / 1024 + "Kbps");
Expand Down Expand Up @@ -298,7 +299,8 @@ private void addVideoSource(String url) {
item.setId(generateViewId());
}
mBinding.playerContainer.addView(item);
getSupportFragmentManager().beginTransaction().add(item.getId(), PlayFragment.newInstance(url, RTSPClient.TRANSTYPE_TCP, null)).commit();
boolean useUDP = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getString(R.string.key_udp_mode), false);
getSupportFragmentManager().beginTransaction().add(item.getId(), PlayFragment.newInstance(url, useUDP ? RTSPClient.TRANSTYPE_UDP : RTSPClient.TRANSTYPE_TCP, null)).commit();
}

/**
Expand Down Expand Up @@ -393,7 +395,10 @@ protected void onCreate(Bundle savedInstanceState) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

if (savedInstanceState == null) {
PlayFragment fragment = PlayFragment.newInstance(url, RTSPClient.TRANSTYPE_TCP, new ResultReceiver(new Handler()) {


boolean useUDP = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getString(R.string.key_udp_mode), false);
PlayFragment fragment = PlayFragment.newInstance(url, useUDP ? RTSPClient.TRANSTYPE_UDP : RTSPClient.TRANSTYPE_TCP, new ResultReceiver(new Handler()) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
Expand Down Expand Up @@ -525,4 +530,8 @@ public void onOpenFileDirectory(View view) {
Intent i = new Intent(this, MediaFilesActivity.class);
startActivity(i);
}

public void onEvent(PlayFragment playFragment, String msg) {
mBinding.msgTxt.setText(msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ public void onClick(View view) {
PlayListViewHolder holder = (PlayListViewHolder) view.getTag();
int pos = holder.getAdapterPosition();
if (pos != -1) {
mCursor.moveToPosition(pos);
String playUrl = mCursor.getString(mCursor.getColumnIndex(VideoSource.URL));
if (!TextUtils.isEmpty(playUrl)) {
Intent i = new Intent(PlaylistActivity.this, PlayActivity.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ protected void onCreate(Bundle savedInstanceState) {
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_setting);
mBinding.serverIp.setText(PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.key_ip), "121.40.50.44"));
mBinding.serverPort.setText(PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.key_port), "8080"));
mBinding.transportMode.setChecked(android.preference.PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getString(R.string.key_udp_mode), false));
}

@Override
Expand All @@ -52,6 +53,7 @@ public void onOK(View view) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
editor.putString(getString(R.string.key_ip), mBinding.serverIp.getText().toString());
editor.putString(getString(R.string.key_port), mBinding.serverPort.getText().toString());
editor.putBoolean(getString(R.string.key_udp_mode), mBinding.transportMode.isChecked());
editor.apply();
finish();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorListenerAdapter;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -192,6 +193,8 @@ public void onViewCreated(final View view, @Nullable Bundle savedInstanceState)
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
if (resultCode == EasyRTSPClient.RESULT_VIDEO_DISPLAYED) {

Log.i(TAG, String.format("VIDEO DISPLAYED!!!!%d*%d", mWidth, mHeight));
// Toast.makeText(PlayActivity.this, "视频正在播放了", Toast.LENGTH_SHORT).show();
view.findViewById(android.R.id.progress).setVisibility(View.GONE);
mSurfaceView.post(new Runnable() {
Expand All @@ -211,6 +214,10 @@ public void run() {
} else if (resultCode == EasyRTSPClient.RESULT_VIDEO_SIZE) {
mWidth = resultData.getInt(EasyRTSPClient.EXTRA_VIDEO_WIDTH);
mHeight = resultData.getInt(EasyRTSPClient.EXTRA_VIDEO_HEIGHT);


Log.i(TAG, String.format("RESULT_VIDEO_SIZE RECEIVED :%d*%d", mWidth, mHeight));

if (mAttacher != null) {
mAttacher.cleanup();
}
Expand All @@ -228,7 +235,14 @@ public void run() {
mAngleView.setVisibility(View.VISIBLE);
}
} else if (resultCode == EasyRTSPClient.RESULT_TIMEOUT) {
Toast.makeText(getActivity(), "试播时间到", Toast.LENGTH_SHORT).show();
new AlertDialog.Builder(getActivity()).setMessage("试播时间到").setTitle("SORRY").setPositiveButton(android.R.string.ok, null).show();
} else if (resultCode == EasyRTSPClient.RESULT_UNSUPPORTED_AUDIO) {
new AlertDialog.Builder(getActivity()).setMessage("音频格式不支持").setTitle("SORRY").setPositiveButton(android.R.string.ok, null).show();
} else if (resultCode == EasyRTSPClient.RESULT_UNSUPPORTED_VIDEO) {
new AlertDialog.Builder(getActivity()).setMessage("视频格式不支持").setTitle("SORRY").setPositiveButton(android.R.string.ok, null).show();
}else if (resultCode == EasyRTSPClient.RESULT_EVENT){
PlayActivity activity = (PlayActivity) getActivity();
activity.onEvent(PlayFragment.this, resultData.getString("event-msg"));
}
}
};
Expand Down Expand Up @@ -298,7 +312,8 @@ protected void fixPlayerRatio(View renderView, int maxWidth, int maxHeight) {

protected void startRending(Surface surface) {
mStreamRender = new EasyRTSPClient(getContext(), "E2E90B0867DBB86BF1450BCD01664592", surface, mResultReceiver);
mStreamRender.start(mUrl, mType, RTSPClient.EASY_SDK_VIDEO_FRAME_FLAG | RTSPClient.EASY_SDK_AUDIO_FRAME_FLAG, "admin", "admin");
mStreamRender.start(mUrl, mType, RTSPClient.EASY_SDK_VIDEO_FRAME_FLAG | RTSPClient.EASY_SDK_AUDIO_FRAME_FLAG, "", "");
// mStreamRender.start2(mUrl, mType);
mRR.send(RESULT_REND_STARTED, null);
}

Expand Down Expand Up @@ -339,6 +354,9 @@ public void onMatrixChanged(RectF rect) {

public void takePicture(final String path) {
try {
if (mWidth <= 0 || mHeight <= 0) {
return;
}
Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
mSurfaceView.getBitmap(bitmap);
saveBitmapInFile(path, bitmap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;

import com.google.gson.Gson;

import org.esaydarwin.rtsp.player.R;

import java.io.IOException;
import android.os.Handler;

import com.google.gson.Gson;

import okhttp3.OkHttpClient;

import okhttp3.Request;
import okhttp3.Response;

Expand Down Expand Up @@ -68,7 +69,7 @@ public void run() {
PackageInfo packageInfo=packageManager.getPackageInfo(mContext.getPackageName(),0);
int localVersionCode=packageInfo.versionCode;
int remoteVersionCode= Integer.valueOf(versionInfo.getVersionCode());
Log.d(TAG, "localVersionCode="+localVersionCode+", remoteVersionCode="+remoteVersionCode);
Log.d(TAG, "kim localVersionCode="+localVersionCode+", remoteVersionCode="+remoteVersionCode);
if(localVersionCode<remoteVersionCode){
mApkUrl = versionInfo.getUrl();
mHandler.post(mShowDlg);
Expand All @@ -89,6 +90,7 @@ public void run() {
*/
private void showUpdateDialog(){
final String apkUrl=mApkUrl;
Log.d(TAG, "kim showUpdateDialog. apkUrl="+apkUrl);
new AlertDialog.Builder(mContext)
.setMessage("EasyPlayer可以升级到更高的版本,是否升级")
.setTitle("升级提示")
Expand Down
Binary file not shown.
Binary file not shown.
12 changes: 11 additions & 1 deletion Android/EasyPlayer/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
android:layout_height="match_parent"
android:divider="?android:attr/listDivider"
android:orientation="vertical"
android:showDividers="middle" />
android:showDividers="middle">
<TextView
android:layout_width="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:id="@+id/msg_txt"
android:layout_height="match_parent" />
</LinearLayout>

</LinearLayout>
</layout>
13 changes: 11 additions & 2 deletions Android/EasyPlayer/src/main/res/layout/activity_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@
android:inputType="number"
android:padding="10dp" />

<CheckBox
android:id="@+id/transport_mode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:text="UDP模式观看视频(如果不勾选,表示使用TCP模式)" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:text="确认修改"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:onClick="onOK"
android:layout_marginTop="@dimen/activity_vertical_margin" />
android:text="确认修改" />
</LinearLayout>
</layout>
14 changes: 7 additions & 7 deletions Android/EasyPlayer/src/main/res/layout/fragment_play.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
android:layout_height="match_parent"
android:layout_gravity="center">

<TextureView
android:id="@+id/surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<ImageView
android:id="@+id/surface_cover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:scaleType="centerCrop"
android:transitionName="video_animation" />
android:scaleType="centerCrop"/>

<TextureView
android:id="@+id/surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />


<ProgressBar
android:id="@android:id/progress"
Expand Down
1 change: 1 addition & 0 deletions Android/EasyPlayer/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="key_ip">KEY_IP</string>
<string name="key_port">KEY_PORT</string>
<string name="key_udp_mode">key_udp_mode</string>
</resources>
2 changes: 1 addition & 1 deletion Android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.2.1'
}
}

Expand Down
4 changes: 2 additions & 2 deletions Android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
#Fri Oct 21 09:48:51 CST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

0 comments on commit 924bb00

Please sign in to comment.