修改为安卓
This commit is contained in:
parent
827c714610
commit
44d4ded7b2
BIN
android-app/.gradle/8.1/checksums/checksums.lock
Normal file
BIN
android-app/.gradle/8.1/checksums/checksums.lock
Normal file
Binary file not shown.
BIN
android-app/.gradle/8.1/checksums/md5-checksums.bin
Normal file
BIN
android-app/.gradle/8.1/checksums/md5-checksums.bin
Normal file
Binary file not shown.
BIN
android-app/.gradle/8.1/checksums/sha1-checksums.bin
Normal file
BIN
android-app/.gradle/8.1/checksums/sha1-checksums.bin
Normal file
Binary file not shown.
Binary file not shown.
BIN
android-app/.gradle/8.1/executionHistory/executionHistory.bin
Normal file
BIN
android-app/.gradle/8.1/executionHistory/executionHistory.bin
Normal file
Binary file not shown.
BIN
android-app/.gradle/8.1/executionHistory/executionHistory.lock
Normal file
BIN
android-app/.gradle/8.1/executionHistory/executionHistory.lock
Normal file
Binary file not shown.
BIN
android-app/.gradle/8.1/fileChanges/last-build.bin
Normal file
BIN
android-app/.gradle/8.1/fileChanges/last-build.bin
Normal file
Binary file not shown.
BIN
android-app/.gradle/8.1/fileHashes/fileHashes.bin
Normal file
BIN
android-app/.gradle/8.1/fileHashes/fileHashes.bin
Normal file
Binary file not shown.
BIN
android-app/.gradle/8.1/fileHashes/fileHashes.lock
Normal file
BIN
android-app/.gradle/8.1/fileHashes/fileHashes.lock
Normal file
Binary file not shown.
BIN
android-app/.gradle/8.1/fileHashes/resourceHashesCache.bin
Normal file
BIN
android-app/.gradle/8.1/fileHashes/resourceHashesCache.bin
Normal file
Binary file not shown.
0
android-app/.gradle/8.1/gc.properties
Normal file
0
android-app/.gradle/8.1/gc.properties
Normal file
BIN
android-app/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Normal file
BIN
android-app/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Normal file
Binary file not shown.
2
android-app/.gradle/buildOutputCleanup/cache.properties
Normal file
2
android-app/.gradle/buildOutputCleanup/cache.properties
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#Mon Dec 15 18:02:26 CST 2025
|
||||
gradle.version=8.1
|
||||
BIN
android-app/.gradle/buildOutputCleanup/outputFiles.bin
Normal file
BIN
android-app/.gradle/buildOutputCleanup/outputFiles.bin
Normal file
Binary file not shown.
2
android-app/.gradle/config.properties
Normal file
2
android-app/.gradle/config.properties
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#Tue Dec 16 09:00:29 CST 2025
|
||||
java.home=C\:\\Program Files\\Android\\Android Studio\\jbr
|
||||
BIN
android-app/.gradle/file-system.probe
Normal file
BIN
android-app/.gradle/file-system.probe
Normal file
Binary file not shown.
0
android-app/.gradle/vcs-1/gc.properties
Normal file
0
android-app/.gradle/vcs-1/gc.properties
Normal file
|
|
@ -0,0 +1,221 @@
|
|||
package com.example.livestreaming;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.example.livestreaming.databinding.ActivityMainBinding;
|
||||
import com.example.livestreaming.databinding.DialogCreateRoomBinding;
|
||||
import com.example.livestreaming.net.ApiClient;
|
||||
import com.example.livestreaming.net.ApiResponse;
|
||||
import com.example.livestreaming.net.CreateRoomRequest;
|
||||
import com.example.livestreaming.net.Room;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private ActivityMainBinding binding;
|
||||
private RoomsAdapter adapter;
|
||||
|
||||
private final Handler handler = new Handler(Looper.getMainLooper());
|
||||
private Runnable pollRunnable;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
binding = ActivityMainBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
adapter = new RoomsAdapter(room -> {
|
||||
if (room == null) return;
|
||||
Intent intent = new Intent(MainActivity.this, RoomDetailActivity.class);
|
||||
intent.putExtra(RoomDetailActivity.EXTRA_ROOM_ID, room.getId());
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
binding.roomsRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
binding.roomsRecyclerView.setAdapter(adapter);
|
||||
|
||||
binding.startLiveButton.setOnClickListener(v -> showCreateRoomDialog());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
startPolling();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
stopPolling();
|
||||
}
|
||||
|
||||
private void startPolling() {
|
||||
stopPolling();
|
||||
pollRunnable = () -> {
|
||||
fetchRooms();
|
||||
handler.postDelayed(pollRunnable, 5000);
|
||||
};
|
||||
handler.post(pollRunnable);
|
||||
}
|
||||
|
||||
private void stopPolling() {
|
||||
if (pollRunnable != null) {
|
||||
handler.removeCallbacks(pollRunnable);
|
||||
pollRunnable = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void showCreateRoomDialog() {
|
||||
DialogCreateRoomBinding dialogBinding = DialogCreateRoomBinding.inflate(getLayoutInflater());
|
||||
|
||||
AlertDialog dialog = new AlertDialog.Builder(this)
|
||||
.setTitle("创建直播间")
|
||||
.setView(dialogBinding.getRoot())
|
||||
.setNegativeButton("取消", null)
|
||||
.setPositiveButton("创建", null)
|
||||
.create();
|
||||
|
||||
dialog.setOnShowListener(d -> {
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
|
||||
String title = dialogBinding.titleEdit.getText() != null ? dialogBinding.titleEdit.getText().toString().trim() : "";
|
||||
String streamer = dialogBinding.streamerEdit.getText() != null ? dialogBinding.streamerEdit.getText().toString().trim() : "";
|
||||
|
||||
if (TextUtils.isEmpty(title)) {
|
||||
dialogBinding.titleLayout.setError("标题不能为空");
|
||||
return;
|
||||
} else {
|
||||
dialogBinding.titleLayout.setError(null);
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(streamer)) {
|
||||
dialogBinding.streamerLayout.setError("主播名称不能为空");
|
||||
return;
|
||||
} else {
|
||||
dialogBinding.streamerLayout.setError(null);
|
||||
}
|
||||
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
||||
|
||||
ApiClient.getService().createRoom(new CreateRoomRequest(title, streamer))
|
||||
.enqueue(new Callback<ApiResponse<Room>>() {
|
||||
@Override
|
||||
public void onResponse(Call<ApiResponse<Room>> call, Response<ApiResponse<Room>> response) {
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
|
||||
|
||||
ApiResponse<Room> body = response.body();
|
||||
Room room = body != null ? body.getData() : null;
|
||||
if (!response.isSuccessful() || room == null) {
|
||||
Toast.makeText(MainActivity.this, "创建失败", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
dialog.dismiss();
|
||||
fetchRooms();
|
||||
|
||||
Intent intent = new Intent(MainActivity.this, RoomDetailActivity.class);
|
||||
intent.putExtra(RoomDetailActivity.EXTRA_ROOM_ID, room.getId());
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ApiResponse<Room>> call, Throwable t) {
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
|
||||
Toast.makeText(MainActivity.this, "网络错误:" + (t != null ? t.getMessage() : ""), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void showStreamInfo(Room room) {
|
||||
String streamKey = room != null ? room.getStreamKey() : null;
|
||||
String rtmp = room != null && room.getStreamUrls() != null ? room.getStreamUrls().getRtmp() : null;
|
||||
|
||||
String rtmpForObs = null;
|
||||
if (!TextUtils.isEmpty(rtmp) && rtmp.contains("10.0.2.2")) {
|
||||
try {
|
||||
Uri u = Uri.parse(rtmp);
|
||||
int port = u.getPort();
|
||||
String path = u.getPath();
|
||||
if (port > 0 && !TextUtils.isEmpty(path)) {
|
||||
rtmpForObs = "rtmp://localhost:" + port + path;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
String msg = "";
|
||||
if (!TextUtils.isEmpty(rtmp)) {
|
||||
msg += "推流地址(服务器):\n" + rtmp + "\n\n";
|
||||
}
|
||||
if (!TextUtils.isEmpty(rtmpForObs)) {
|
||||
msg += "电脑本机 OBS 可用(等价地址):\n" + rtmpForObs + "\n\n";
|
||||
}
|
||||
if (!TextUtils.isEmpty(streamKey)) {
|
||||
msg += "推流密钥(Stream Key):\n" + streamKey + "\n\n";
|
||||
}
|
||||
msg += "提示:用 OBS 推流时,服务器填上面的推流地址,密钥填 streamKey。";
|
||||
|
||||
String copyRtmp = rtmp;
|
||||
String copyKey = streamKey;
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("已创建直播间")
|
||||
.setMessage(msg)
|
||||
.setNegativeButton("复制地址", (d, w) -> copyToClipboard("rtmp", copyRtmp))
|
||||
.setPositiveButton("复制密钥", (d, w) -> copyToClipboard("streamKey", copyKey))
|
||||
.show();
|
||||
}
|
||||
|
||||
private void copyToClipboard(String label, String text) {
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
Toast.makeText(this, "内容为空", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||
if (cm == null) return;
|
||||
cm.setPrimaryClip(ClipData.newPlainText(label, text));
|
||||
Toast.makeText(this, "已复制", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private void fetchRooms() {
|
||||
binding.loading.setVisibility(View.VISIBLE);
|
||||
|
||||
ApiClient.getService().getRooms().enqueue(new Callback<ApiResponse<List<Room>>>() {
|
||||
@Override
|
||||
public void onResponse(Call<ApiResponse<List<Room>>> call, Response<ApiResponse<List<Room>>> response) {
|
||||
binding.loading.setVisibility(View.GONE);
|
||||
ApiResponse<List<Room>> body = response.body();
|
||||
List<Room> rooms = body != null && body.getData() != null ? body.getData() : Collections.emptyList();
|
||||
adapter.submitList(rooms);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ApiResponse<List<Room>>> call, Throwable t) {
|
||||
binding.loading.setVisibility(View.GONE);
|
||||
adapter.submitList(Collections.emptyList());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
package com.example.livestreaming;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.common.PlaybackException;
|
||||
import androidx.media3.common.Player;
|
||||
import androidx.media3.exoplayer.ExoPlayer;
|
||||
|
||||
import com.example.livestreaming.databinding.ActivityPlayerBinding;
|
||||
|
||||
public class PlayerActivity extends AppCompatActivity {
|
||||
|
||||
public static final String EXTRA_PLAY_URL = "extra_play_url";
|
||||
public static final String EXTRA_TITLE = "extra_title";
|
||||
|
||||
private ActivityPlayerBinding binding;
|
||||
private ExoPlayer player;
|
||||
private boolean triedAltUrl = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
binding = ActivityPlayerBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
String t = getIntent().getStringExtra(EXTRA_TITLE);
|
||||
setTitle(t != null ? t : "Live");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
String url = getIntent().getStringExtra(EXTRA_PLAY_URL);
|
||||
if (url == null || url.trim().isEmpty()) return;
|
||||
|
||||
triedAltUrl = false;
|
||||
|
||||
ExoPlayer exo = new ExoPlayer.Builder(this).build();
|
||||
binding.playerView.setPlayer(exo);
|
||||
|
||||
String altUrl = getAltHlsUrl(url);
|
||||
exo.addListener(new Player.Listener() {
|
||||
@Override
|
||||
public void onPlayerError(PlaybackException error) {
|
||||
if (triedAltUrl) return;
|
||||
if (altUrl == null || altUrl.trim().isEmpty()) return;
|
||||
triedAltUrl = true;
|
||||
|
||||
exo.setMediaItem(MediaItem.fromUri(altUrl));
|
||||
exo.prepare();
|
||||
exo.setPlayWhenReady(true);
|
||||
}
|
||||
});
|
||||
|
||||
exo.setMediaItem(MediaItem.fromUri(url));
|
||||
exo.prepare();
|
||||
exo.setPlayWhenReady(true);
|
||||
player = exo;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
if (player != null) {
|
||||
player.release();
|
||||
player = null;
|
||||
}
|
||||
}
|
||||
|
||||
private String getAltHlsUrl(String url) {
|
||||
if (!url.endsWith(".m3u8")) return null;
|
||||
if (url.contains("/index.m3u8")) return null;
|
||||
|
||||
return url.substring(0, url.length() - ".m3u8".length()) + "/index.m3u8";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,301 @@
|
|||
package com.example.livestreaming;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.common.PlaybackException;
|
||||
import androidx.media3.common.Player;
|
||||
import androidx.media3.exoplayer.ExoPlayer;
|
||||
|
||||
import com.example.livestreaming.databinding.ActivityRoomDetailBinding;
|
||||
import com.example.livestreaming.net.ApiClient;
|
||||
import com.example.livestreaming.net.ApiResponse;
|
||||
import com.example.livestreaming.net.Room;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class RoomDetailActivity extends AppCompatActivity {
|
||||
|
||||
public static final String EXTRA_ROOM_ID = "extra_room_id";
|
||||
|
||||
private ActivityRoomDetailBinding binding;
|
||||
private final Handler handler = new Handler(Looper.getMainLooper());
|
||||
private Runnable pollRunnable;
|
||||
|
||||
private String roomId;
|
||||
private Room room;
|
||||
|
||||
private ExoPlayer player;
|
||||
private boolean triedAltUrl;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
binding = ActivityRoomDetailBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
roomId = getIntent().getStringExtra(EXTRA_ROOM_ID);
|
||||
|
||||
binding.backButton.setOnClickListener(v -> finish());
|
||||
binding.copyRtmpButton.setOnClickListener(v -> {
|
||||
String alt = binding.rtmpAltValue.getText() != null ? binding.rtmpAltValue.getText().toString() : null;
|
||||
if (!TextUtils.isEmpty(alt) && binding.rtmpAltGroup.getVisibility() == View.VISIBLE) {
|
||||
copyToClipboard("rtmp", alt);
|
||||
return;
|
||||
}
|
||||
String raw = binding.rtmpValue.getText() != null ? binding.rtmpValue.getText().toString() : null;
|
||||
copyToClipboard("rtmp", raw);
|
||||
});
|
||||
binding.copyKeyButton.setOnClickListener(v -> copyToClipboard("streamKey", binding.keyValue.getText() != null ? binding.keyValue.getText().toString() : null));
|
||||
binding.deleteButton.setOnClickListener(v -> confirmDelete());
|
||||
|
||||
triedAltUrl = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
startPolling();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
stopPolling();
|
||||
releasePlayer();
|
||||
}
|
||||
|
||||
private void startPolling() {
|
||||
stopPolling();
|
||||
pollRunnable = () -> {
|
||||
fetchRoom();
|
||||
handler.postDelayed(pollRunnable, 5000);
|
||||
};
|
||||
handler.post(pollRunnable);
|
||||
}
|
||||
|
||||
private void stopPolling() {
|
||||
if (pollRunnable != null) {
|
||||
handler.removeCallbacks(pollRunnable);
|
||||
pollRunnable = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchRoom() {
|
||||
if (TextUtils.isEmpty(roomId)) {
|
||||
Toast.makeText(this, "房间不存在", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
binding.loading.setVisibility(View.VISIBLE);
|
||||
|
||||
ApiClient.getService().getRoom(roomId).enqueue(new Callback<ApiResponse<Room>>() {
|
||||
@Override
|
||||
public void onResponse(Call<ApiResponse<Room>> call, Response<ApiResponse<Room>> response) {
|
||||
binding.loading.setVisibility(View.GONE);
|
||||
|
||||
ApiResponse<Room> body = response.body();
|
||||
Room data = body != null ? body.getData() : null;
|
||||
if (!response.isSuccessful() || data == null) {
|
||||
Toast.makeText(RoomDetailActivity.this, "房间不存在", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
room = data;
|
||||
bindRoom(room);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ApiResponse<Room>> call, Throwable t) {
|
||||
binding.loading.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void bindRoom(Room r) {
|
||||
setTitle(r.getTitle() != null ? r.getTitle() : "Room");
|
||||
|
||||
binding.titleText.setText(r.getTitle() != null ? r.getTitle() : "(Untitled)");
|
||||
binding.streamerText.setText(r.getStreamerName() != null ? ("主播: " + r.getStreamerName()) : "");
|
||||
|
||||
binding.liveBadge.setText(r.isLive() ? "直播中" : "未开播");
|
||||
int badgeColor = ContextCompat.getColor(this, r.isLive() ? R.color.live_red : android.R.color.darker_gray);
|
||||
binding.liveBadge.setBackgroundColor(badgeColor);
|
||||
|
||||
String rtmp = r.getStreamUrls() != null ? r.getStreamUrls().getRtmp() : null;
|
||||
String key = r.getStreamKey();
|
||||
|
||||
binding.rtmpValue.setText(rtmp != null ? rtmp : "");
|
||||
binding.keyValue.setText(key != null ? key : "");
|
||||
|
||||
String altRtmp = getAltRtmpForObs(rtmp);
|
||||
binding.rtmpAltValue.setText(altRtmp != null ? altRtmp : "");
|
||||
binding.rtmpAltGroup.setVisibility(!TextUtils.isEmpty(altRtmp) ? View.VISIBLE : View.GONE);
|
||||
|
||||
if (!r.isLive()) {
|
||||
binding.playerContainer.setVisibility(View.GONE);
|
||||
binding.offlineHint.setVisibility(View.VISIBLE);
|
||||
releasePlayer();
|
||||
return;
|
||||
}
|
||||
|
||||
binding.offlineHint.setVisibility(View.GONE);
|
||||
binding.playerContainer.setVisibility(View.VISIBLE);
|
||||
|
||||
String playUrl = null;
|
||||
if (r.getStreamUrls() != null) {
|
||||
playUrl = r.getStreamUrls().getHls();
|
||||
if (playUrl == null || playUrl.trim().isEmpty()) {
|
||||
playUrl = r.getStreamUrls().getFlv();
|
||||
}
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(playUrl)) {
|
||||
releasePlayer();
|
||||
return;
|
||||
}
|
||||
|
||||
if (r.getStreamUrls() != null) {
|
||||
String hls = r.getStreamUrls().getHls();
|
||||
String flv = r.getStreamUrls().getFlv();
|
||||
if (TextUtils.isEmpty(hls) && !TextUtils.isEmpty(flv)) {
|
||||
Toast.makeText(this, "提示:当前没有 HLS 地址,Android 可能无法播放 FLV。建议在后端启用 FFmpeg/HLS。", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
ensurePlayer(playUrl);
|
||||
}
|
||||
|
||||
private void ensurePlayer(String url) {
|
||||
if (!TextUtils.isEmpty(url) && url.endsWith(".flv")) {
|
||||
Toast.makeText(this, "提示:Android 原生播放器可能无法播放 FLV,如黑屏请启用 HLS。", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
if (player != null) {
|
||||
MediaItem current = player.getCurrentMediaItem();
|
||||
String currentUri = current != null && current.localConfiguration != null && current.localConfiguration.uri != null
|
||||
? current.localConfiguration.uri.toString()
|
||||
: null;
|
||||
|
||||
if (currentUri != null && currentUri.equals(url)) return;
|
||||
}
|
||||
|
||||
releasePlayer();
|
||||
|
||||
triedAltUrl = false;
|
||||
|
||||
ExoPlayer exo = new ExoPlayer.Builder(this).build();
|
||||
binding.playerView.setPlayer(exo);
|
||||
|
||||
String altUrl = getAltHlsUrl(url);
|
||||
exo.addListener(new Player.Listener() {
|
||||
@Override
|
||||
public void onPlayerError(PlaybackException error) {
|
||||
if (triedAltUrl) return;
|
||||
if (TextUtils.isEmpty(altUrl)) return;
|
||||
triedAltUrl = true;
|
||||
|
||||
exo.setMediaItem(MediaItem.fromUri(altUrl));
|
||||
exo.prepare();
|
||||
exo.setPlayWhenReady(true);
|
||||
}
|
||||
});
|
||||
|
||||
exo.setMediaItem(MediaItem.fromUri(url));
|
||||
exo.prepare();
|
||||
exo.setPlayWhenReady(true);
|
||||
player = exo;
|
||||
}
|
||||
|
||||
private void releasePlayer() {
|
||||
if (player != null) {
|
||||
player.release();
|
||||
player = null;
|
||||
}
|
||||
if (binding != null) binding.playerView.setPlayer(null);
|
||||
}
|
||||
|
||||
private String getAltHlsUrl(String url) {
|
||||
if (url == null) return null;
|
||||
if (!url.endsWith(".m3u8")) return null;
|
||||
if (url.contains("/index.m3u8")) return null;
|
||||
return url.substring(0, url.length() - ".m3u8".length()) + "/index.m3u8";
|
||||
}
|
||||
|
||||
private String getAltRtmpForObs(String rtmp) {
|
||||
if (TextUtils.isEmpty(rtmp)) return null;
|
||||
if (!rtmp.contains("10.0.2.2")) return null;
|
||||
|
||||
try {
|
||||
Uri u = Uri.parse(rtmp);
|
||||
int port = u.getPort();
|
||||
String path = u.getPath();
|
||||
if (port > 0 && !TextUtils.isEmpty(path)) {
|
||||
return "rtmp://localhost:" + port + path;
|
||||
}
|
||||
return null;
|
||||
} catch (Exception ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void copyToClipboard(String label, String text) {
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
Toast.makeText(this, "内容为空", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||
if (cm == null) return;
|
||||
cm.setPrimaryClip(ClipData.newPlainText(label, text));
|
||||
Toast.makeText(this, "已复制", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private void confirmDelete() {
|
||||
if (TextUtils.isEmpty(roomId)) return;
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("删除房间")
|
||||
.setMessage("确定删除该直播间吗?")
|
||||
.setNegativeButton("取消", null)
|
||||
.setPositiveButton("删除", (d, w) -> deleteRoom())
|
||||
.show();
|
||||
}
|
||||
|
||||
private void deleteRoom() {
|
||||
binding.loading.setVisibility(View.VISIBLE);
|
||||
|
||||
ApiClient.getService().deleteRoom(roomId).enqueue(new Callback<ApiResponse<Object>>() {
|
||||
@Override
|
||||
public void onResponse(Call<ApiResponse<Object>> call, Response<ApiResponse<Object>> response) {
|
||||
binding.loading.setVisibility(View.GONE);
|
||||
if (!response.isSuccessful()) {
|
||||
Toast.makeText(RoomDetailActivity.this, "删除失败", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
Toast.makeText(RoomDetailActivity.this, "已删除", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ApiResponse<Object>> call, Throwable t) {
|
||||
binding.loading.setVisibility(View.GONE);
|
||||
Toast.makeText(RoomDetailActivity.this, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
package com.example.livestreaming;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.ListAdapter;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.example.livestreaming.databinding.ItemRoomBinding;
|
||||
import com.example.livestreaming.net.Room;
|
||||
|
||||
public class RoomsAdapter extends ListAdapter<Room, RoomsAdapter.RoomVH> {
|
||||
|
||||
public interface OnRoomClickListener {
|
||||
void onRoomClick(Room room);
|
||||
}
|
||||
|
||||
private final OnRoomClickListener onRoomClick;
|
||||
|
||||
public RoomsAdapter(OnRoomClickListener onRoomClick) {
|
||||
super(DIFF);
|
||||
this.onRoomClick = onRoomClick;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RoomVH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
ItemRoomBinding binding = ItemRoomBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||
return new RoomVH(binding, onRoomClick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RoomVH holder, int position) {
|
||||
holder.bind(getItem(position));
|
||||
}
|
||||
|
||||
static class RoomVH extends RecyclerView.ViewHolder {
|
||||
|
||||
private final ItemRoomBinding binding;
|
||||
private final OnRoomClickListener onRoomClick;
|
||||
|
||||
RoomVH(ItemRoomBinding binding, OnRoomClickListener onRoomClick) {
|
||||
super(binding.getRoot());
|
||||
this.binding = binding;
|
||||
this.onRoomClick = onRoomClick;
|
||||
}
|
||||
|
||||
void bind(Room room) {
|
||||
binding.roomTitle.setText(room != null && room.getTitle() != null ? room.getTitle() : "(Untitled)");
|
||||
binding.streamerName.setText(room != null && room.getStreamerName() != null ? room.getStreamerName() : "");
|
||||
|
||||
if (room != null && room.isLive()) {
|
||||
binding.liveBadge.setVisibility(View.VISIBLE);
|
||||
binding.liveBadge.setBackgroundColor(ContextCompat.getColor(binding.getRoot().getContext(), R.color.live_red));
|
||||
} else {
|
||||
binding.liveBadge.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
binding.getRoot().setOnClickListener(v -> {
|
||||
if (room == null) return;
|
||||
if (onRoomClick != null) onRoomClick.onRoomClick(room);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static final DiffUtil.ItemCallback<Room> DIFF = new DiffUtil.ItemCallback<Room>() {
|
||||
@Override
|
||||
public boolean areItemsTheSame(@NonNull Room oldItem, @NonNull Room newItem) {
|
||||
String o = oldItem.getId();
|
||||
String n = newItem.getId();
|
||||
return o != null && o.equals(n);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areContentsTheSame(@NonNull Room oldItem, @NonNull Room newItem) {
|
||||
return oldItem.equals(newItem);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.example.livestreaming.net;
|
||||
|
||||
import com.example.livestreaming.BuildConfig;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public final class ApiClient {
|
||||
|
||||
private static volatile Retrofit retrofit;
|
||||
private static volatile ApiService service;
|
||||
|
||||
private ApiClient() {
|
||||
}
|
||||
|
||||
public static ApiService getService() {
|
||||
if (service != null) return service;
|
||||
synchronized (ApiClient.class) {
|
||||
if (service != null) return service;
|
||||
|
||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
|
||||
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
|
||||
|
||||
OkHttpClient client = new OkHttpClient.Builder()
|
||||
.addInterceptor(logging)
|
||||
.build();
|
||||
|
||||
retrofit = new Retrofit.Builder()
|
||||
.baseUrl(BuildConfig.API_BASE_URL)
|
||||
.client(client)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build();
|
||||
|
||||
service = retrofit.create(ApiService.class);
|
||||
return service;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.example.livestreaming.net;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class ApiResponse<T> {
|
||||
|
||||
@SerializedName("success")
|
||||
private Boolean success;
|
||||
|
||||
@SerializedName("data")
|
||||
private T data;
|
||||
|
||||
public Boolean getSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.example.livestreaming.net;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.DELETE;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Path;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface ApiService {
|
||||
@GET("rooms")
|
||||
Call<ApiResponse<List<Room>>> getRooms();
|
||||
|
||||
@POST("rooms")
|
||||
Call<ApiResponse<Room>> createRoom(@Body CreateRoomRequest body);
|
||||
|
||||
@GET("rooms/{id}")
|
||||
Call<ApiResponse<Room>> getRoom(@Path("id") String id);
|
||||
|
||||
@DELETE("rooms/{id}")
|
||||
Call<ApiResponse<Object>> deleteRoom(@Path("id") String id);
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.example.livestreaming.net;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class CreateRoomRequest {
|
||||
|
||||
@SerializedName("title")
|
||||
private final String title;
|
||||
|
||||
@SerializedName("streamerName")
|
||||
private final String streamerName;
|
||||
|
||||
public CreateRoomRequest(String title, String streamerName) {
|
||||
this.title = title;
|
||||
this.streamerName = streamerName;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getStreamerName() {
|
||||
return streamerName;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
package com.example.livestreaming.net;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Room {
|
||||
|
||||
@SerializedName("id")
|
||||
private String id;
|
||||
|
||||
@SerializedName("title")
|
||||
private String title;
|
||||
|
||||
@SerializedName("streamerName")
|
||||
private String streamerName;
|
||||
|
||||
@SerializedName("streamKey")
|
||||
private String streamKey;
|
||||
|
||||
@SerializedName("isLive")
|
||||
private boolean isLive;
|
||||
|
||||
@SerializedName("streamUrls")
|
||||
private StreamUrls streamUrls;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getStreamerName() {
|
||||
return streamerName;
|
||||
}
|
||||
|
||||
public String getStreamKey() {
|
||||
return streamKey;
|
||||
}
|
||||
|
||||
public boolean isLive() {
|
||||
return isLive;
|
||||
}
|
||||
|
||||
public StreamUrls getStreamUrls() {
|
||||
return streamUrls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Room)) return false;
|
||||
Room room = (Room) o;
|
||||
return isLive == room.isLive
|
||||
&& Objects.equals(id, room.id)
|
||||
&& Objects.equals(title, room.title)
|
||||
&& Objects.equals(streamerName, room.streamerName)
|
||||
&& Objects.equals(streamKey, room.streamKey)
|
||||
&& Objects.equals(streamUrls, room.streamUrls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, title, streamerName, streamKey, isLive, streamUrls);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.example.livestreaming.net;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class StreamUrls {
|
||||
|
||||
@SerializedName("rtmp")
|
||||
private String rtmp;
|
||||
|
||||
@SerializedName("flv")
|
||||
private String flv;
|
||||
|
||||
@SerializedName("hls")
|
||||
private String hls;
|
||||
|
||||
public String getRtmp() {
|
||||
return rtmp;
|
||||
}
|
||||
|
||||
public String getFlv() {
|
||||
return flv;
|
||||
}
|
||||
|
||||
public String getHls() {
|
||||
return hls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof StreamUrls)) return false;
|
||||
StreamUrls that = (StreamUrls) o;
|
||||
return Objects.equals(rtmp, that.rtmp)
|
||||
&& Objects.equals(flv, that.flv)
|
||||
&& Objects.equals(hls, that.hls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(rtmp, flv, hls);
|
||||
}
|
||||
}
|
||||
211
android-app/app/src/main/res/layout/activity_room_detail.xml
Normal file
211
android-app/app/src/main/res/layout/activity_room_detail.xml
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/loading"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:id="@+id/scroll"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:fillViewport="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/backButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="返回"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/liveBadge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="10dp"
|
||||
android:paddingVertical="6dp"
|
||||
android:text="未开播"
|
||||
android:textColor="@android:color/white"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="Room"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/backButton" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/streamerText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:text="主播: "
|
||||
android:textColor="#666666"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/titleText" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/playerContainer"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="220dp"
|
||||
android:layout_marginTop="14dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/streamerText">
|
||||
|
||||
<androidx.media3.ui.PlayerView
|
||||
android:id="@+id/playerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/offlineHint"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="14dp"
|
||||
android:gravity="center"
|
||||
android:padding="18dp"
|
||||
android:text="主播暂未开播"
|
||||
android:textColor="#666666"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/streamerText" />
|
||||
|
||||
<androidx.constraintlayout.widget.Barrier
|
||||
android:id="@+id/playerOrOfflineBarrier"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:barrierDirection="bottom"
|
||||
app:constraint_referenced_ids="playerContainer,offlineHint" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/streamInfoTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="18dp"
|
||||
android:text="推流信息"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/playerOrOfflineBarrier" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/rtmpLayout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/streamInfoTitle">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/rtmpValue"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusable="false"
|
||||
android:hint="推流地址"
|
||||
android:inputType="textUri" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/copyRtmpButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="复制地址"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/rtmpLayout" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/rtmpAltGroup"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
app:constraint_referenced_ids="rtmpAltLayout" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/rtmpAltLayout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/copyRtmpButton">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/rtmpAltValue"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusable="false"
|
||||
android:hint="电脑本机 OBS 可用(等价地址)"
|
||||
android:inputType="textUri" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/keyLayout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/rtmpAltLayout">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/keyValue"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusable="false"
|
||||
android:hint="推流密钥"
|
||||
android:inputType="text" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/copyKeyButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="复制密钥"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/keyLayout" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/deleteButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="18dp"
|
||||
android:text="删除房间"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/copyKeyButton" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
41
android-app/app/src/main/res/layout/dialog_create_room.xml
Normal file
41
android-app/app/src/main/res/layout/dialog_create_room.xml
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="20dp">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/titleLayout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/titleEdit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="直播间标题"
|
||||
android:inputType="text" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/streamerLayout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/titleLayout">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/streamerEdit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="主播昵称"
|
||||
android:inputType="textPersonName" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
BIN
android-app/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
android-app/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
android-app/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
android-app/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=file:///D:/soft/gradle-8.1-bin.zip
|
||||
networkTimeout=600000
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
245
android-app/gradlew
vendored
Normal file
245
android-app/gradlew
vendored
Normal file
|
|
@ -0,0 +1,245 @@
|
|||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
92
android-app/gradlew.bat
vendored
Normal file
92
android-app/gradlew.bat
vendored
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
8
android-app/local.properties
Normal file
8
android-app/local.properties
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
## This file must *NOT* be checked into Version Control Systems,
|
||||
# as it contains information specific to your local configuration.
|
||||
#
|
||||
# Location of the SDK. This is only used by Gradle.
|
||||
# For customization when using a Version Control System, please read the
|
||||
# header note.
|
||||
#Tue Dec 16 09:00:29 CST 2025
|
||||
sdk.dir=C\:\\Users\\Administrator\\AppData\\Local\\Android\\Sdk
|
||||
Loading…
Reference in New Issue
Block a user