ionic-chromecast 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -1
- package/android/src/main/AndroidManifest.xml +5 -0
- package/android/src/main/java/com/fabianacevedo/ionicchromecast/CastOptionsProvider.java +10 -11
- package/android/src/main/java/com/fabianacevedo/ionicchromecast/IonicChromecast.java +383 -211
- package/android/src/main/java/com/fabianacevedo/ionicchromecast/IonicChromecastPlugin.java +120 -206
- package/dist/docs.json +10 -0
- package/dist/esm/definitions.d.ts +7 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +4 -0
- package/dist/esm/web.js +4 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +4 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +4 -0
- package/dist/plugin.js.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ A Capacitor plugin for integrating Google Cast SDK (Chromecast) with Ionic/Capac
|
|
|
8
8
|
- ✅ Session management (request, check status)
|
|
9
9
|
- ✅ Device discovery
|
|
10
10
|
- ✅ Media playback with rich metadata
|
|
11
|
+
- ✅ End active Cast session from app
|
|
11
12
|
- ✅ Android support
|
|
12
13
|
- ✅ Event listeners
|
|
13
14
|
- 🚧 iOS support (coming soon)
|
|
@@ -41,7 +42,8 @@ import { IonicChromecast } from 'ionic-chromecast';
|
|
|
41
42
|
// In your app.component.ts or main initialization
|
|
42
43
|
async initializeCast() {
|
|
43
44
|
const result = await IonicChromecast.initialize({
|
|
44
|
-
|
|
45
|
+
// Prefer CastVideos CAF receiver for reliable UI on TV. Use 'CC1AD845' if you need the default.
|
|
46
|
+
receiverApplicationId: '4F8B3483'
|
|
45
47
|
});
|
|
46
48
|
|
|
47
49
|
if (result.success) {
|
|
@@ -95,6 +97,14 @@ async playVideo() {
|
|
|
95
97
|
console.log('▶️ Video is playing on TV!');
|
|
96
98
|
}
|
|
97
99
|
}
|
|
100
|
+
|
|
101
|
+
// Optional: end the current Cast session from the app
|
|
102
|
+
async stopCasting() {
|
|
103
|
+
const result = await IonicChromecast.endSession();
|
|
104
|
+
if (result.success) {
|
|
105
|
+
console.log('⏹ Cast session ended');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
98
108
|
```
|
|
99
109
|
|
|
100
110
|
## Complete Examples
|
|
@@ -275,6 +285,10 @@ export class CastControlPage implements OnDestroy {
|
|
|
275
285
|
// Clean up listeners
|
|
276
286
|
this.eventListeners.forEach(handle => handle.remove());
|
|
277
287
|
}
|
|
288
|
+
|
|
289
|
+
async stopCast() {
|
|
290
|
+
await IonicChromecast.endSession();
|
|
291
|
+
}
|
|
278
292
|
}
|
|
279
293
|
```
|
|
280
294
|
|
|
@@ -345,6 +359,7 @@ export class CastButtonComponent implements OnInit {
|
|
|
345
359
|
* [`isSessionActive()`](#issessionactive)
|
|
346
360
|
* [`areDevicesAvailable()`](#aredevicesavailable)
|
|
347
361
|
* [`loadMedia(...)`](#loadmedia)
|
|
362
|
+
* [`endSession()`](#endsession)
|
|
348
363
|
* [`addListener(ChromecastEventType, ...)`](#addlistenerchromecasteventtype-)
|
|
349
364
|
* [Interfaces](#interfaces)
|
|
350
365
|
* [Type Aliases](#type-aliases)
|
|
@@ -443,6 +458,19 @@ Load media on the Cast device (Android only)
|
|
|
443
458
|
--------------------
|
|
444
459
|
|
|
445
460
|
|
|
461
|
+
### endSession()
|
|
462
|
+
|
|
463
|
+
```typescript
|
|
464
|
+
endSession() => Promise<{ success: boolean; message?: string; }>
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
End the current Cast session (Android only)
|
|
468
|
+
|
|
469
|
+
**Returns:** <code>Promise<{ success: boolean; message?: string; }></code>
|
|
470
|
+
|
|
471
|
+
--------------------
|
|
472
|
+
|
|
473
|
+
|
|
446
474
|
### addListener(ChromecastEventType, ...)
|
|
447
475
|
|
|
448
476
|
```typescript
|
|
@@ -538,3 +566,8 @@ Listen to Chromecast events (Android only)
|
|
|
538
566
|
<code>'sessionStarted' | 'sessionEnded' | 'mediaLoaded' | 'mediaError' | 'deviceAvailable' | 'deviceUnavailable' | 'volumeChanged' | 'playbackStatusChanged'</code>
|
|
539
567
|
|
|
540
568
|
</docgen-api>
|
|
569
|
+
|
|
570
|
+
## Troubleshooting
|
|
571
|
+
- No Cast UI on TV after connecting: use the CastVideos CAF receiver ID `4F8B3483` instead of the default `CC1AD845` when calling `initialize`.
|
|
572
|
+
- Media returns success but nothing plays: confirm a session is active (`isSessionActive`), then retry `loadMedia` with a known-good HTTPS MP4 (e.g., BigBuckBunny).
|
|
573
|
+
- Devices not found: ensure the phone and Chromecast are on the same WiFi and Google Play Services is up to date.
|
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
<uses-permission android:name="android.permission.INTERNET" />
|
|
5
5
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
6
6
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
|
7
|
+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
|
8
|
+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
9
|
+
<uses-permission
|
|
10
|
+
android:name="android.permission.NEARBY_WIFI_DEVICES"
|
|
11
|
+
android:usesPermissionFlags="neverForLocation" />
|
|
7
12
|
|
|
8
13
|
<application>
|
|
9
14
|
<!-- Google Cast OptionsProvider -->
|
|
@@ -10,39 +10,38 @@ import java.util.List;
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* OptionsProvider for Google Cast SDK
|
|
13
|
-
* This class is required by the Cast SDK to provide configuration options
|
|
14
13
|
*/
|
|
15
14
|
public class CastOptionsProvider implements OptionsProvider {
|
|
16
|
-
|
|
17
|
-
// Default Media Receiver App ID (Google's default receiver)
|
|
15
|
+
|
|
18
16
|
private static final String DEFAULT_RECEIVER_APP_ID = "CC1AD845";
|
|
19
17
|
private static final String PREFS_NAME = "IonicChromecastPrefs";
|
|
20
18
|
private static final String KEY_RECEIVER_APP_ID = "receiverApplicationId";
|
|
21
|
-
|
|
22
|
-
// Static variable to hold the receiver app ID before CastContext is initialized
|
|
19
|
+
|
|
23
20
|
public static String sReceiverApplicationId = null;
|
|
24
|
-
|
|
21
|
+
|
|
25
22
|
@Override
|
|
26
23
|
public CastOptions getCastOptions(Context context) {
|
|
27
24
|
String receiverAppId = DEFAULT_RECEIVER_APP_ID;
|
|
28
|
-
|
|
29
|
-
//
|
|
25
|
+
|
|
26
|
+
// Prefer static variable set by initialize()
|
|
30
27
|
if (sReceiverApplicationId != null && !sReceiverApplicationId.isEmpty()) {
|
|
31
28
|
receiverAppId = sReceiverApplicationId;
|
|
32
29
|
} else {
|
|
33
|
-
//
|
|
30
|
+
// Try from SharedPreferences
|
|
34
31
|
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
|
35
32
|
String savedId = prefs.getString(KEY_RECEIVER_APP_ID, null);
|
|
36
33
|
if (savedId != null && !savedId.isEmpty()) {
|
|
37
34
|
receiverAppId = savedId;
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
|
-
|
|
37
|
+
|
|
41
38
|
return new CastOptions.Builder()
|
|
42
39
|
.setReceiverApplicationId(receiverAppId)
|
|
40
|
+
.setStopReceiverApplicationWhenEndingSession(true)
|
|
41
|
+
.setResumeSavedSession(false)
|
|
43
42
|
.build();
|
|
44
43
|
}
|
|
45
|
-
|
|
44
|
+
|
|
46
45
|
@Override
|
|
47
46
|
public List<SessionProvider> getAdditionalSessionProviders(Context context) {
|
|
48
47
|
return null;
|