Chromecast 发件人应用程序未连接到 Android Receiver 应用程序,始终连接到 Web 接收器
Posted
技术标签:
【中文标题】Chromecast 发件人应用程序未连接到 Android Receiver 应用程序,始终连接到 Web 接收器【英文标题】:Chromecast sender application isn't connecting to Android Receiver app , always connecting to web receiver 【发布时间】:2021-07-23 15:45:26 【问题描述】:我关注了这个代码实验室 Cast Connect with ATV App 和这个代码实验室 Cast-enable an android app ,之后
我在 cast 控制台中添加了我的 Chromecast 作为测试设备 签署 ATV 应用程序 安装在电视盒中并尝试从发件人应用程序投射,但它打开网络接收器而不是 ATV 应用程序 发件人 AndroidManifest.xml <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="video/* , application/x-mpegURL" />
</intent>
</queries>
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:protectionLevel="signature"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.JMXPlayer"
android:usesCleartextTraffic="true"
tools:ignore="UnusedAttribute">
<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
android:value="com.stream.jmxplayer.casty.CastOptionProvider" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Sender Option Provider 类
public class CastOptionProvider implements OptionsProvider
@Override
public CastOptions getCastOptions(Context context)
CastOptions customCastOptions = Casty.customCastOptions;
if (customCastOptions == null)
List<String> buttonActions = createButtonActions();
int[] compatButtonAction = 1, 3;
NotificationOptions notificationOptions = new NotificationOptions.Builder()
.setActions(buttonActions, compatButtonAction)
.setTargetActivityClassName(ExpandedControlsActivity.class.getName())
.build();
CastMediaOptions mediaOptions = new CastMediaOptions.Builder()
.setNotificationOptions(notificationOptions)
.setExpandedControllerActivityClassName(ExpandedControlsActivity.class.getName())
.build();
LaunchOptions launchOptions = new LaunchOptions.Builder()
.setRelaunchIfRunning(true)
.setAndroidReceiverCompatible(true).build();
return new CastOptions.Builder()
.setReceiverApplicationId(Casty.receiverId)
.setCastMediaOptions(mediaOptions)
.setLaunchOptions(launchOptions)
.build();
else
return customCastOptions;
private List<String> createButtonActions()
return Arrays.asList(MediaIntentReceiver.ACTION_REWIND,
MediaIntentReceiver.ACTION_TOGGLE_PLAYBACK,
MediaIntentReceiver.ACTION_FORWARD,
MediaIntentReceiver.ACTION_STOP_CASTING);
@Override
public List<SessionProvider> getAdditionalSessionProviders(Context context)
return null;
接收者 AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-feature
android:name="android.software.leanback"
android:required="true" />
<application
android:name=".JmxApplication"
android:allowBackup="true"
android:appComponentFactory="androidx.core.app.CoreComponentFactory"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.JMXPlayerCast">
<meta-data
android:name="com.google.android.gms.cast.tv.RECEIVER_OPTIONS_PROVIDER_CLASS_NAME"
android:value="com.stream.jmxplayercast.CastReceiverOptionsProvider" />
<activity
android:name=".ui.MainActivity"
android:banner="@drawable/main_logo"
android:label="@string/app_name"
android:launchMode="singleTask"
android:logo="@drawable/circle_cropped_logo"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.gms.cast.tv.action.LAUNCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ui.PlayerActivity"
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="com.google.android.gms.cast.tv.action.LOAD" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:mimeType="video/*" />
<data android:mimeType="application/*" />
</intent-filter>
</activity>
</application>
ReceiverOptionProver 类是 vanilla codelab 的选项提供者。 我做错了什么以及如何解决这个问题.. 提前致谢
【问题讨论】:
【参考方案1】:代码没问题。我的错误是 APP_ID 放错了。
【讨论】:
以上是关于Chromecast 发件人应用程序未连接到 Android Receiver 应用程序,始终连接到 Web 接收器的主要内容,如果未能解决你的问题,请参考以下文章