mirror of
https://framagit.org/tom79/fedilab-tube
synced 2025-06-05 21:09:11 +02:00
Some improvements with cast
This commit is contained in:
@ -114,6 +114,8 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
|
|||||||
public static ChromeCast chromeCast;
|
public static ChromeCast chromeCast;
|
||||||
private VideoData.Video castedTube;
|
private VideoData.Video castedTube;
|
||||||
|
|
||||||
|
public static boolean chromecastActivated = false;
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
@SuppressLint("ApplySharedPref")
|
||||||
public static void showRadioButtonDialogFullInstances(Activity activity, boolean storeInDb) {
|
public static void showRadioButtonDialogFullInstances(Activity activity, boolean storeInDb) {
|
||||||
final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
@ -212,15 +214,6 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void newChromeCastDiscovered(ChromeCast chromeCast) {
|
public void newChromeCastDiscovered(ChromeCast chromeCast) {
|
||||||
try {
|
|
||||||
if (chromeCast.isAppRunning(Helper.CAST_ID) && chromeCast.getMediaStatus() != null && chromeCast.getMediaStatus().playerState != null) {
|
|
||||||
if (binding.castInfo.getVisibility() == View.GONE) {
|
|
||||||
binding.castInfo.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (chromeCasts == null) {
|
if (chromeCasts == null) {
|
||||||
chromeCasts = new ArrayList<>();
|
chromeCasts = new ArrayList<>();
|
||||||
chromeCasts.add(chromeCast);
|
chromeCasts.add(chromeCast);
|
||||||
@ -236,6 +229,15 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
|
|||||||
chromeCasts.add(chromeCast);
|
chromeCasts.add(chromeCast);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
if (chromeCast.isAppRunning(Helper.CAST_ID) && chromeCast.getMediaStatus() != null && chromeCast.getMediaStatus().playerState != null) {
|
||||||
|
if (binding.castInfo.getVisibility() == View.GONE) {
|
||||||
|
binding.castInfo.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,6 +258,7 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
|
|||||||
if (chromeCasts != null && chromeCasts.size() > 0) {
|
if (chromeCasts != null && chromeCasts.size() > 0) {
|
||||||
for (ChromeCast cast : chromeCasts) {
|
for (ChromeCast cast : chromeCasts) {
|
||||||
try {
|
try {
|
||||||
|
cast.stopApp();
|
||||||
cast.disconnect();
|
cast.disconnect();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -430,16 +433,13 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
|
|||||||
PlaylistExportHelper.manageIntentUrl(MainActivity.this, getIntent());
|
PlaylistExportHelper.manageIntentUrl(MainActivity.this, getIntent());
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.castClose.setOnClickListener(v -> new Thread(() -> {
|
binding.castClose.setOnClickListener(v -> {
|
||||||
try {
|
Intent intentBC = new Intent(Helper.RECEIVE_CAST_SETTINGS);
|
||||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
Bundle b = new Bundle();
|
||||||
chromeCast.disconnect();
|
b.putInt("displayed", 0);
|
||||||
Runnable myRunnable = () -> binding.castTogglePlay.setVisibility(View.GONE);
|
intentBC.putExtras(b);
|
||||||
mainHandler.post(myRunnable);
|
LocalBroadcastManager.getInstance(MainActivity.this).sendBroadcast(intentBC);
|
||||||
} catch (IOException e) {
|
});
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
binding.castTogglePlay.setOnClickListener(v -> {
|
binding.castTogglePlay.setOnClickListener(v -> {
|
||||||
if (chromeCast != null) {
|
if (chromeCast != null) {
|
||||||
@ -484,6 +484,7 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
|
|||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
if (chromeCast != null) {
|
if (chromeCast != null) {
|
||||||
|
chromeCast.stopApp();
|
||||||
chromeCast.disconnect();
|
chromeCast.disconnect();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -492,6 +493,7 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
|
|||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
if (displayed == 1) {
|
if (displayed == 1) {
|
||||||
|
chromecastActivated = true;
|
||||||
if (castedTube != null) {
|
if (castedTube != null) {
|
||||||
binding.castInfo.setVisibility(View.VISIBLE);
|
binding.castInfo.setVisibility(View.VISIBLE);
|
||||||
Helper.loadGiF(MainActivity.this, castedTube.getThumbnailPath(), binding.castView);
|
Helper.loadGiF(MainActivity.this, castedTube.getThumbnailPath(), binding.castView);
|
||||||
@ -499,16 +501,17 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
|
|||||||
binding.castDescription.setText(castedTube.getDescription());
|
binding.castDescription.setText(castedTube.getDescription());
|
||||||
}
|
}
|
||||||
} else if (displayed == 0) {
|
} else if (displayed == 0) {
|
||||||
|
chromecastActivated = false;
|
||||||
|
binding.castInfo.setVisibility(View.GONE);
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
if (chromeCast != null) {
|
if (chromeCast != null) {
|
||||||
chromeCast.disconnect();
|
chromeCast.stopApp();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
binding.castInfo.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -158,6 +158,7 @@ import su.litvak.chromecast.api.v2.Status;
|
|||||||
|
|
||||||
import static app.fedilab.fedilabtube.MainActivity.chromeCast;
|
import static app.fedilab.fedilabtube.MainActivity.chromeCast;
|
||||||
import static app.fedilab.fedilabtube.MainActivity.chromeCasts;
|
import static app.fedilab.fedilabtube.MainActivity.chromeCasts;
|
||||||
|
import static app.fedilab.fedilabtube.MainActivity.chromecastActivated;
|
||||||
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.ADD_COMMENT;
|
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.ADD_COMMENT;
|
||||||
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.RATEVIDEO;
|
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.RATEVIDEO;
|
||||||
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPLY;
|
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPLY;
|
||||||
@ -738,7 +739,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||||||
}
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
for (ChromeCast cc : chromeCasts) {
|
for (ChromeCast cc : chromeCasts) {
|
||||||
if (cc.isConnected()) {
|
if (chromecastActivated && cc.isConnected()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
@ -748,15 +749,12 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||||||
chromeCast = chromeCasts.get(position);
|
chromeCast = chromeCasts.get(position);
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
if (chromeCast != null) {
|
if (chromeCast != null) {
|
||||||
if (chromeCast.isConnected()) {
|
if (chromecastActivated) {
|
||||||
Intent intentBC = new Intent(Helper.RECEIVE_CAST_SETTINGS);
|
Intent intentBC = new Intent(Helper.RECEIVE_CAST_SETTINGS);
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
b.putInt("displayed", 0);
|
b.putInt("displayed", 0);
|
||||||
intentBC.putExtras(b);
|
intentBC.putExtras(b);
|
||||||
LocalBroadcastManager.getInstance(PeertubeActivity.this).sendBroadcast(intentBC);
|
LocalBroadcastManager.getInstance(PeertubeActivity.this).sendBroadcast(intentBC);
|
||||||
try {
|
|
||||||
chromeCast.disconnect();
|
|
||||||
chromeCast = null;
|
|
||||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
Runnable myRunnable = () -> {
|
Runnable myRunnable = () -> {
|
||||||
binding.doubleTapPlayerView.setVisibility(View.VISIBLE);
|
binding.doubleTapPlayerView.setVisibility(View.VISIBLE);
|
||||||
@ -764,9 +762,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||||||
};
|
};
|
||||||
mainHandler.post(myRunnable);
|
mainHandler.post(myRunnable);
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Intent intentBC = new Intent(Helper.RECEIVE_CAST_SETTINGS);
|
Intent intentBC = new Intent(Helper.RECEIVE_CAST_SETTINGS);
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
@ -802,7 +797,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||||||
|
|
||||||
if (chromeCastVideoURL != null) {
|
if (chromeCastVideoURL != null) {
|
||||||
String mime = MimeTypeMap.getFileExtensionFromUrl(chromeCastVideoURL);
|
String mime = MimeTypeMap.getFileExtensionFromUrl(chromeCastVideoURL);
|
||||||
chromeCast.setRequestTimeout(120000);
|
chromeCast.setRequestTimeout(60000);
|
||||||
chromeCast.load(peertube.getTitle(), null, chromeCastVideoURL, mime);
|
chromeCast.load(peertube.getTitle(), null, chromeCastVideoURL, mime);
|
||||||
chromeCast.play();
|
chromeCast.play();
|
||||||
binding.castPlay.setImageResource(R.drawable.ic_baseline_pause_32);
|
binding.castPlay.setImageResource(R.drawable.ic_baseline_pause_32);
|
||||||
@ -1419,15 +1414,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||||||
if (torrentStream != null && torrentStream.isStreaming()) {
|
if (torrentStream != null && torrentStream.isStreaming()) {
|
||||||
torrentStream.stopStream();
|
torrentStream.stopStream();
|
||||||
}
|
}
|
||||||
if (chromeCast != null && chromeCast.isConnected()) {
|
|
||||||
new Thread(() -> {
|
|
||||||
try {
|
|
||||||
chromeCast.disconnect();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
unregisterReceiver();
|
unregisterReceiver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +131,8 @@
|
|||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_margin="5dp"
|
android:layout_margin="5dp"
|
||||||
android:contentDescription="@string/play"
|
android:contentDescription="@string/play"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
android:src="@drawable/ic_baseline_pause_32" />
|
android:src="@drawable/ic_baseline_pause_32" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
@ -140,6 +142,8 @@
|
|||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_margin="5dp"
|
android:layout_margin="5dp"
|
||||||
android:contentDescription="@string/close"
|
android:contentDescription="@string/close"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
android:src="@drawable/ic_baseline_close_white_24" />
|
android:src="@drawable/ic_baseline_close_white_24" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user