Skip to content

Commit 7003fa8

Browse files
プレイヤーの画面にデバッグログを表示できるように修正
1 parent 2086fca commit 7003fa8

16 files changed

Lines changed: 244 additions & 8 deletions

File tree

dConnectSDK/dConnectLibStreaming/rtsp-player-app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
android:name=".RTSPPlayerActivity"
2828
android:exported="false"
2929
android:parentActivityName=".MainActivity" />
30+
31+
<activity
32+
android:name=".RTSPSettingPreferenceActivity"
33+
android:exported="false"
34+
android:parentActivityName=".MainActivity" />
3035
</application>
3136

3237
</manifest>

dConnectSDK/dConnectLibStreaming/rtsp-player-app/src/main/java/org/deviceconnect/android/rtspplayer/MainActivity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
6363

6464
//noinspection SimplifiableIfStatement
6565
if (id == R.id.action_settings) {
66+
gotoPreferences();
6667
return true;
6768
}
6869

6970
return super.onOptionsItemSelected(item);
7071
}
7172

73+
private void gotoPreferences() {
74+
Intent intent = new Intent();
75+
intent.setClass(getApplicationContext(), RTSPSettingPreferenceActivity.class);
76+
startActivity(intent);
77+
}
78+
7279
private void gotoRTSPPlayer(String uri) {
7380
Intent intent = new Intent();
7481
intent.setClass(getApplicationContext(), RTSPPlayerActivity.class);

dConnectSDK/dConnectLibStreaming/rtsp-player-app/src/main/java/org/deviceconnect/android/rtspplayer/RTSPPlayerActivity.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
import android.view.View;
99
import android.view.ViewGroup;
1010
import android.widget.ProgressBar;
11+
import android.widget.TextView;
1112

1213
import org.deviceconnect.android.libmedia.streaming.rtsp.player.RtspPlayer;
1314

15+
import java.util.ArrayList;
16+
import java.util.List;
17+
1418
import androidx.appcompat.app.AlertDialog;
1519
import androidx.appcompat.app.AppCompatActivity;
1620

@@ -19,11 +23,17 @@ public class RTSPPlayerActivity extends AppCompatActivity {
1923
static final String EXTRA_URI = "_extra_uri";
2024

2125
private RtspPlayer mRtspPlayer;
26+
private RTSPSetting mSetting;
2227

2328
@Override
2429
protected void onCreate(Bundle savedInstanceState) {
2530
super.onCreate(savedInstanceState);
2631
setContentView(R.layout.activity_rtsp_player);
32+
33+
mSetting = new RTSPSetting(getApplicationContext());
34+
35+
int visibility = mSetting.isEnabledDebugLog() ? View.VISIBLE : View.GONE;
36+
findViewById(R.id.text_view_debug).setVisibility(visibility);
2737
}
2838

2939
@Override
@@ -65,19 +75,23 @@ private void startPlayer() {
6575
mRtspPlayer.setOnEventListener(new RtspPlayer.OnEventListener() {
6676
@Override
6777
public void onConnected() {
78+
addDebugLog("サーバに接続しました。");
6879
}
6980

7081
@Override
7182
public void onDisconnected() {
83+
addDebugLog("サーバから切断されました。");
7284
}
7385

7486
@Override
7587
public void onReady() {
88+
addDebugLog("SDP を受信しました。");
7689
runOnUiThread(() -> progressBar.setVisibility(View.GONE));
7790
}
7891

7992
@Override
8093
public void onSizeChanged(int width, int height) {
94+
addDebugLog("サイズ変更: " + width + "x" + height);
8195
runOnUiThread(() -> changePlayerSize(width, height));
8296
}
8397

@@ -97,6 +111,33 @@ private void stopPlayer() {
97111
}
98112
}
99113

114+
private final List<String> mDebugMessage = new ArrayList<>();
115+
116+
private void addDebugLog(String message) {
117+
synchronized (mDebugMessage) {
118+
mDebugMessage.add(message);
119+
120+
if (mDebugMessage.size() > 5) {
121+
mDebugMessage.remove(0);
122+
}
123+
}
124+
runOnUiThread(() -> {
125+
TextView textView = findViewById(R.id.text_view_debug);
126+
127+
StringBuilder sb = new StringBuilder();
128+
synchronized (mDebugMessage) {
129+
for (String s : mDebugMessage) {
130+
if (sb.length() > 0) {
131+
sb.append("\n");
132+
}
133+
sb.append(s);
134+
}
135+
}
136+
137+
textView.setText(sb.toString());
138+
});
139+
}
140+
100141
private void showErrorDialog(String title, String message) {
101142
runOnUiThread(() ->
102143
new AlertDialog.Builder(this)

dConnectSDK/dConnectLibStreaming/rtsp-player-app/src/main/java/org/deviceconnect/android/rtspplayer/RTSPSetting.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@
44
import android.content.SharedPreferences;
55
import android.preference.PreferenceManager;
66

7-
public class RTSPSetting {
7+
class RTSPSetting {
88

99
private SharedPreferences mSharedPreferences;
1010

11-
public RTSPSetting(Context context) {
11+
RTSPSetting(Context context) {
1212
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
1313
}
1414

15-
16-
public void setServerUrl(String url) {
15+
void setServerUrl(String url) {
1716
SharedPreferences.Editor editor = mSharedPreferences.edit();
1817
editor.putString("rtsp_server_url", url);
1918
editor.apply();
2019
}
2120

22-
public String getServerUrl() {
21+
String getServerUrl() {
2322
return mSharedPreferences.getString("rtsp_server_url", null);
2423
}
24+
25+
boolean isEnabledDebugLog() {
26+
return mSharedPreferences.getBoolean("settings_debug_log", true);
27+
}
2528
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.deviceconnect.android.rtspplayer;
2+
3+
import android.os.Bundle;
4+
import android.view.MenuItem;
5+
6+
import androidx.appcompat.app.ActionBar;
7+
import androidx.appcompat.app.AppCompatActivity;
8+
import androidx.preference.PreferenceFragmentCompat;
9+
10+
public class RTSPSettingPreferenceActivity extends AppCompatActivity {
11+
12+
@Override
13+
protected void onCreate(Bundle savedInstanceState) {
14+
super.onCreate(savedInstanceState);
15+
setContentView(R.layout.activity_settings);
16+
17+
ActionBar actionBar = getSupportActionBar();
18+
if (actionBar != null) {
19+
actionBar.setDisplayHomeAsUpEnabled(true);
20+
actionBar.setHomeButtonEnabled(true);
21+
actionBar.setTitle(R.string.settings_name);
22+
}
23+
24+
getSupportFragmentManager()
25+
.beginTransaction()
26+
.replace(R.id.settings_container, new RtspPreferenceFragment())
27+
.commit();
28+
}
29+
30+
@Override
31+
public boolean onOptionsItemSelected(MenuItem item) {
32+
int id = item.getItemId();
33+
if (id == android.R.id.home) {
34+
finish();
35+
return true;
36+
}
37+
return super.onOptionsItemSelected(item);
38+
}
39+
40+
public static class RtspPreferenceFragment extends PreferenceFragmentCompat {
41+
@Override
42+
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
43+
setPreferencesFromResource(R.xml.rtsp_settings, rootKey);
44+
}
45+
}
46+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="#FFFFFF"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="#FF000000" android:pathData="M19.1,12.9a2.8,2.8 0,0 0,0.1 -0.9,2.8 2.8,0 0,0 -0.1,-0.9l2.1,-1.6a0.7,0.7 0,0 0,0.1 -0.6L19.4,5.5a0.7,0.7 0,0 0,-0.6 -0.2l-2.4,1a6.5,6.5 0,0 0,-1.6 -0.9l-0.4,-2.6a0.5,0.5 0,0 0,-0.5 -0.4H10.1a0.5,0.5 0,0 0,-0.5 0.4L9.3,5.4a5.6,5.6 0,0 0,-1.7 0.9l-2.4,-1a0.4,0.4 0,0 0,-0.5 0.2l-2,3.4c-0.1,0.2 0,0.4 0.2,0.6l2,1.6a2.8,2.8 0,0 0,-0.1 0.9,2.8 2.8,0 0,0 0.1,0.9L2.8,14.5a0.7,0.7 0,0 0,-0.1 0.6l1.9,3.4a0.7,0.7 0,0 0,0.6 0.2l2.4,-1a6.5,6.5 0,0 0,1.6 0.9l0.4,2.6a0.5,0.5 0,0 0,0.5 0.4h3.8a0.5,0.5 0,0 0,0.5 -0.4l0.3,-2.6a5.6,5.6 0,0 0,1.7 -0.9l2.4,1a0.4,0.4 0,0 0,0.5 -0.2l2,-3.4c0.1,-0.2 0,-0.4 -0.2,-0.6ZM12,15.6A3.6,3.6 0,1 1,15.6 12,3.6 3.6,0 0,1 12,15.6Z"/>
5+
</vector>

dConnectSDK/dConnectLibStreaming/rtsp-player-app/src/main/res/layout/activity_rtsp_player.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,24 @@
2727
app:layout_constraintBottom_toBottomOf="parent"
2828
app:layout_constraintEnd_toEndOf="parent" />
2929

30+
<androidx.constraintlayout.widget.Guideline
31+
android:id="@+id/guideline_1"
32+
android:layout_width="wrap_content"
33+
android:layout_height="wrap_content"
34+
android:orientation="vertical"
35+
app:layout_constraintGuide_percent="0.45" />
36+
37+
<TextView
38+
android:id="@+id/text_view_debug"
39+
android:layout_width="0dp"
40+
android:layout_height="wrap_content"
41+
android:background="#4000"
42+
android:textColor="#fff"
43+
android:padding="4dp"
44+
android:layout_margin="4dp"
45+
android:textSize="12sp"
46+
app:layout_constraintTop_toTopOf="parent"
47+
app:layout_constraintLeft_toLeftOf="parent"
48+
app:layout_constraintRight_toRightOf="@id/guideline_1" />
49+
3050
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context="org.deviceconnect.android.rtspplayer.RTSPSettingPreferenceActivity">
8+
9+
<FrameLayout
10+
android:id="@+id/settings_container"
11+
android:layout_width="match_parent"
12+
android:layout_height="match_parent" />
13+
14+
</androidx.constraintlayout.widget.ConstraintLayout>

dConnectSDK/dConnectLibStreaming/rtsp-player-app/src/main/res/menu/menu_main.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
xmlns:app="http://schemas.android.com/apk/res-auto"
33
xmlns:tools="http://schemas.android.com/tools"
44
tools:context="org.deviceconnect.android.rtspplayer.MainActivity">
5+
56
<item
67
android:id="@+id/action_settings"
8+
android:icon="@drawable/ic_settings_black_24dp"
79
android:orderInCategory="100"
810
android:title="@string/action_settings"
9-
app:showAsAction="never"/>
11+
app:showAsAction="always" />
12+
1013
</menu>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<resources>
22
<string name="app_name">RtspPlayer</string>
33
<string name="action_settings">Settings</string>
4+
<string name="settings_name">RTSP 設定</string>
45
</resources>

0 commit comments

Comments
 (0)