This Google Cast demo app shows how to cast videos from an iOS device in a way that is fully compliant with the Cast Design Checklist.

Related tags

Video CastVideos-ios
Overview

CastVideos-ios (reference iOS sender app)

This Google Cast demo app shows how to cast videos from an iOS device in a way that is fully compliant with the Cast Design Checklist.

This is a reference sender app to be used as the starting point for your iOS sender app. The project contains targets for both Objective-C and Swift.

List of reference apps and tutorials

Dependencies

Setup Instructions

  1. Get a Google Cast device and get it set up for development: https://developers.google.com/cast/docs/developers#setup_for_development.
  2. [Optional] Register an application on the Developers Console http://cast.google.com/publish. You will get an App ID when you finish registering your application. This project uses a published Application ID that can be used to run the app without using your own ID but if you need to do any console debugging, you would need to have your own ID.
    • If you use DRM, you will need to use your own App ID.
  3. Setup the project dependencies in Xcode using Cocoapods, installing the tool if necessary: See this guide.
  4. In the root folder, run pod repo update and then pod install.
  5. Open the .xcworkspace file rather the the xcproject to ensure you have the pod dependencies.
  6. The AppDelegate.swift/AppDelegate.m includes a published receiver App ID so the project can be built and run without a need to register an ID.
    • Update this value with your own App ID to use your own receiver to debug and use DRM.
  7. The Info.plist lists the published receiver App ID for NSBonjourServices which is used to discover Cast devices.
    • Update this value with your own App ID if you are using a custom receiver.
  8. For additional setup steps, see the Xcode setup guide.

Documentation

References

How to report bugs

Contributions

Please read and follow the steps in the CONTRIBUTING.md.

License

See LICENSE.

Terms

Your use of this sample is subject to, and by using or downloading the sample files you agree to comply with, the Google APIs Terms of Service and the Google Cast SDK Additional Developer Terms of Service.

Comments
  • Cast button not showing up

    Cast button not showing up

    There is the code to add the cast button to the view controllers as UIBarButtonItem, but when i run the app it doesn't show up.Could I be missing something?

    opened by tobitech 14
  • GCKUIStyle.sharedInstance() crashes app

    GCKUIStyle.sharedInstance() crashes app

    When calling GCKUIStyle.sharedInstance() the app crashes with the following message:

    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: playImage)'

    I'm using Xcode 11.3 and SDK version 4.4.4.

    Does anyone know how to solve?

    opened by sky-digital 8
  • The SDK is gigantic starting with 4.3.x

    The SDK is gigantic starting with 4.3.x

    Something went off the rails between 4.2 and 4.3 of the SDK.

    $ ls -sh */GoogleCast.framework/GoogleCast
     46M GoogleCastSDK-ios-4.2.0/GoogleCast.framework/GoogleCast
    631M GoogleCastSDK-ios-4.3.1_static/GoogleCast.framework/GoogleCast
    

    631MB? Is this a joke?

    opened by pepasflo 8
  • Can't cast .m3u8 videos

    Can't cast .m3u8 videos

    In the demo I replaced the default .mp4 MediaInformations with a .m3u8 video, the local player works fine and the video plays as expected, but when I try to cast it, it fails (Shows a blackscreen with the "SAMPLE" words on it).

    This is the MediaInformation I'm using

    let mediaInfo = GCKMediaInformation(contentID: "https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8", streamType: .buffered,
                                                contentType: "application/x-mpegURL", metadata: metadata,
                                                streamDuration: kGCKInvalidTimeInterval,
                                                mediaTracks: nil,
                                                textTrackStyle: nil, customData: nil)
    

    And this are some of the logs the app is showing.

    MediaViewController: sessionManager didStartSession <0x106567460: GCKCastSession; state = 2>
    switchToRemotePlayback; mediaInfo is Optional(<0x105bcd930: GCKMediaInformation; contentID = https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8>)
    loading media: Optional(<0x105bcd930: GCKMediaInformation; contentID = https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8>)
    removeMediaPlayerObservers
    removeMediaPlayerObservers
    setNavigationBarStyle: Default
    SHOW NavBar.
    configureControls stopped
    didTouchControl stopped
    hideNavigationBar: did touch control
    SHOW NavBar.
    MediaViewController: sessionManager didStartSession <0x106567460: GCKCastSession; state = 2>
    fullscreen=false
    setMediaInfo
    setMediaInfo
    hideToolBar stopped
    setMediaInfo
    

    the logs shows that the media is being loaded to Chromecast but for some reason it's not playing properly. Any help? am I missing something in my MediaInformation or should be m3u8 loaded differently?

    opened by bjimenezned 8
  • Crash related to entering background

    Crash related to entering background

    Fabric:

    Fatal Exception: NSInvalidArgumentException -[__NSCFString appDidEnterBackground]: unrecognized selector sent to instance 0x174427940

    Fatal Exception: NSInvalidArgumentException
    0  CoreFoundation                 0x1838602d8 __exceptionPreprocess
    1  libobjc.A.dylib                0x1950340e4 objc_exception_throw
    2  CoreFoundation                 0x1838673a4 __methodDescriptionForSelector
    3  CoreFoundation                 0x183864154 ___forwarding___
    4  CoreFoundation                 0x183766ccc _CF_forwarding_prep_0
    5  CoreFoundation                 0x1838062c4 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
    6  CoreFoundation                 0x183743450 _CFXNotificationPost
    7  Foundation                     0x184672a80 -[NSNotificationCenter postNotificationName:object:userInfo:]
    8  UIKit                          0x188530358 -[UIApplication _handleApplicationDectivationWithScene:shouldForceExit:transitionContext:completion:]
    9  UIKit                          0x188538dcc __88-[UIApplication _handleApplicationLifecycleEventWithScene:transitionContext:completion:]_block_invoke
    10 UIKit                          0x188538d54 -[UIApplication _handleApplicationLifecycleEventWithScene:transitionContext:completion:]
    11 UIKit                          0x18852bfe0 -[UIApplication scene:didUpdateWithDiff:transitionContext:completion:]
    12 FrontBoardServices             0x18c0713c8 __31-[FBSSerialQueue performAsync:]_block_invoke_2
    13 CoreFoundation                 0x18381827c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__
    14 CoreFoundation                 0x183817384 __CFRunLoopDoBlocks
    15 CoreFoundation                 0x1838159a8 __CFRunLoopRun
    16 CoreFoundation                 0x1837412d4 CFRunLoopRunSpecific
    17 GraphicsServices               0x18cf5f6fc GSEventRunModal
    18 UIKit                          0x188306fac UIApplicationMain
    19 ***                0x1001bc264 main (main.m:14)
    20 libdyld.dylib                  0x1956b2a08 start
    

    Grep:

    Timurs-MacBook-Pro-3:*** bernikowich$ grep -lr "appDidEnterBackground" * | grep -v .svn | grep -v .md
    Pods/google-cast-sdk/GoogleCastSDK-Public-3.1.1-Release/GoogleCast.framework/GoogleCast
    Pods/google-cast-sdk/GoogleCastSDK-Public-3.1.1-Release/GoogleCast.framework/Versions/A/GoogleCast
    Pods/google-cast-sdk/GoogleCastSDK-Public-3.1.1-Release/GoogleCast.framework/Versions/Current/GoogleCast
    ***/xcuserdata/bernikowich.xcuserdatad/UserInterfaceState.xcuserstate
    

    Operating Systems:

    8 - 98%; 9 - 1%; 10 - 1%

    Version: - google-cast-sdk (3.1.1):

    opened by bernikowich-cedoni 6
  • Change color of miniController slider progress view and Volume slider in connection controller

    Change color of miniController slider progress view and Volume slider in connection controller

    I would assume that GCKUIStyle.sharedInstance().castViews.mediaControl.sliderProgressColor = .green and GCKUIStyle.sharedInstance().castViews.deviceControl.sliderProgressColor = .green would work but it doesn't It only changes the color of the slider in the ExpandedController. I don't see another way to change this colors in the docs

    Am I doing something wrong or is it a bug in the stlyer?

    opened by bjimenezned 5
  • Android TV Not Detected

    Android TV Not Detected

    Hi

    I am using Google cast sdk 3.3.0 and it is working fine with Chromecast device.

    But its not detecting Sony Android TV with chromecast built in.

    Do we need any extra setup to make it work?

    Thanks

    opened by rangav 5
  • Can not init  GCKMediaMetadata with key

    Can not init GCKMediaMetadata with key

    I am using the GoogleCastSDK inside my Framework Target ( using as an Umbrella Framework) , hence maybe I am facing issue using the Constant at runtime "kGCKMetadataKeyTitle". That is why I used string @"kGCKMetadataKeyTitle".

    Q1. The following code is not return instance of GCKMediaMetadata ( i.e it is nil ) ?

    GCKMediaMetadata *metadata = [[GCKMediaMetadata alloc] initWithMetadataType:GCKMediaMetadataTypeMovie];
    [metadata setString:@"Movie Title" forKey:@"kGCKMetadataKeyTitle"];
    

    So can I use other string instead of static string given by SDK ?

    I am trying to create GCKMediaInformation following the documentation - GCKMediaInformation

    Q2. Which of the fields of GCKMediaInformation are optional and which are not, as I am getting nil for following code .

    GCKMediaInformation *info = [[GCKMediaInformation alloc] initWithContentID: contentID
                 streamType: streamType
                 contentType: contentType
                 metadata: metadata
                 streamDuration: streamDuration
                 mediaTracks: nil
                 textTrackStyle: textTrackStyle
                 customData: nil]; 
    

    So of-course as metadata is nil, maybe MediaInformation will be nil, but that is not clearly mentioned on documentation which of the fields are required ?

    opened by bishalg 4
  • No devices detected/device scannner not scanning when toggling airplane mode from within app

    No devices detected/device scannner not scanning when toggling airplane mode from within app

    We've implemented logic to reconnect to devices as they come online, but we're running into an issue where the user swipes up to reveal the control center and turns airplane mode on, then repeats the action to turn airplane mode back off. When this occurs, all the devices go offline as expected, but the deviceScanner will not start scanning (with a breakpoint I see the _scanning property's value as NO) even after I call startScan. No devices are ever detected, presumably because the scanner is not and will not scan until I background the app and then return to it. Once backgrounding/returning to the app occurs, the scanner starts scanning and devices are immediately detected and come online. Is there anything else I can do to force the deviceScanner to start scanning without having to background and return to the app?

    opened by tomlindeman 4
  • [GCKDatabase initWithEmpty:inMemory:runtimeConfiguration:] crash on iOS < 11

    [GCKDatabase initWithEmpty:inMemory:runtimeConfiguration:] crash on iOS < 11

    Hello,

    I have a cryptic crash happening on initialization of my app which includes the Chromecast SDK. The crash happens intermediately after launch and only on iOS < 11 (10 and 9 confirmed)

    The class involved is GCKDatabase which looks like an internal class. It is private and has no documentation so debugging is extremely difficult.

    The application crashes in an Enterprise distribution only and doesn't crash when exported locally using XCode.

    What possible causes must i consider?

    Thanks

    opened by piterwilson 3
  • App in Background disconnect device by closing socket

    App in Background disconnect device by closing socket

    Hello. My name is Filip Thanks for your helpful source. I'm using this to integrate and expand our project for casting media. But i'm getting trouble with some issues.

    • First, When the app goes into background, the google cast sdk close the socket, so my iphone disconnected from cast device.

    I need to keep the session and not disconnect.

    • Second, when i disconnected from device, i retry to connect manually, but i'm getting the following errors.

    [GCKDeviceAuthChannel timerDidFire:] authentication timed out [GCKCastDeviceConnector deviceAuthChannel:didFailToAuthenticateWithError:] Not an authentic device, disconnecting. Error Domain=com.google.GCKError Code=3 "Device authentication failure" UserInfo={NSLocalizedDescription=Device authentication failure}

    I don't understand why is that. When i try to connect first, there is no authentication error, but i retry to connect secondly, i'm getting authentication error.

    Please help me. This is urgen issue for our project.

    Thanks. Regards.

    opened by iris112 3
  • Dispatch call

    Dispatch call

    pod 'google-cast-sdk', '~> 4.7.0'

    /googlemac/iPhone/Chromecast/SDK/SecurityLib/Classes/GCKSSecurityTrust.m:59 This method should not be called on the main thread as it may lead to UI unresponsiveness.

    Screenshot 2023-01-06 at 17 04 56
    opened by inastatkic 0
  • M3U8 url not casting

    M3U8 url not casting

    Please find below code and let me know if i need to improve it.

    let metadata = GCKMediaMetadata()
            metadata.setString("Title", forKey: kGCKMetadataKeyTitle)
            metadata.setString("Description",
                               forKey: kGCKMetadataKeySubtitle)
            let media = "https://image.service.eu.axinom.net/transform/1ps4il9bhmzdb8fmbml2eljsf-blvdwdf0x2iapb6izcdztvvw2/QtXvVVHBiVmQdTEftUENzq.png?h=360&w=480"
          
            metadata.addImage(GCKImage(url: URL(string: media)!,
                                       width: 480,
                                       height: 360))
            let url = URL.init(string: "https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.ism/.m3u8")
            guard let mediaURL = url else {
              print("invalid mediaURL")
              return
            }
    
            let mediaInfoBuilder = GCKMediaInformationBuilder(contentURL: mediaURL)
            mediaInfoBuilder.streamType = .buffered;
            mediaInfoBuilder.contentType =  "application/x-mpegURL"
            mediaInfoBuilder.metadata = metadata;
            let mediaInformation = mediaInfoBuilder.build()
            if let request = sessionManager.currentSession?.remoteMediaClient?.loadMedia(mediaInformation) {
              request.delegate = self
            }
    
    opened by rahul-bangde-persistent 0
  • Casting session is not being ended after the user kills the application

    Casting session is not being ended after the user kills the application

    SDK Version: google-cast-sdk (4.6.1) iOS: 16.0

    Expectation:

    • Once I kill the application the current ongoing session should be ended currently it continually playing the video

    What I have tried:

    • Uses of end session:
        func applicationWillTerminate(_ application: UIApplication) {
                 GCKCastContext.sharedInstance().discoveryManager.stopDiscovery()
                 GCKCastContext.sharedInstance().sessionManager.endSession()
                 GCKCastContext.sharedInstance().sessionManager.endSessionAndStopCasting(true)
        }
    
    opened by chirag05k 0
  • Crash inside Cast SDK iOS if a video is too short and contains ads request at the same time.

    Crash inside Cast SDK iOS if a video is too short and contains ads request at the same time.

    Hello!

    I found that if a video is short and contains ads request at the same time - it crashes inside Google Cast SDK for iOS in this component [GCKUIMediaController computeAdBlocks:]

    I can provide sample app for this issue. I downloaded Cast sample app for iOS and just added one my method func makeNewItem() -> GCKMediaInformation which creates "problematic" item. This item contains short video - https://storage.googleapis.com/interactive-media-ads/media/blank-0.2-sec.m4v and VMAP ad tag url.

    Steps to reproduce

    1. Run the app
    2. Connect to Chromecast and play any video from the list with "Play now" option
    3. I substitute the original item with the problematic item. In almost 100% of cases the app will crash with this crash stack below when the ad start on the Chromecast device
    4. I found that this crash is not occurred if the video file duration is longer

    2022-12-02 08:44:28.630554+0600 CastVideos-swift[42068:611451] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil' *** First throw call stack: ( 0 CoreFoundation 0x0000000112d478cb __exceptionPreprocess + 242 1 libobjc.A.dylib 0x000000010dc25ba3 objc_exception_throw + 48 2 CoreFoundation 0x0000000112dcf039 -[__NSCFString characterAtIndex:].cold.1 + 0 3 CoreFoundation 0x0000000112dcc595 -[__NSArrayM insertObject:atIndex:].cold.2 + 0 4 CoreFoundation 0x0000000112c31c18 -[__NSArrayM insertObject:atIndex:] + 993 5 CastVideos-swift 0x0000000104da6cbb +[GCKUIMediaController computeAdBlocks:] + 1095 6 CastVideos-swift 0x0000000104da722d -[GCKUIMediaController remoteMediaClientDidUpdateProgress:] + 71 7 CastVideos-swift 0x0000000104e459b5 -[GCKRemoteMediaClient notifyDidUpdateProgress] + 218 8 CastVideos-swift 0x0000000104ebec62 -[GCKBWeakTimerTarget timerDidFire:] + 89 9 Foundation 0x0000000114385266 __NSFireTimer + 67 10 CoreFoundation 0x0000000112ca7819 CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 20 11 CoreFoundation 0x0000000112ca7363 __CFRunLoopDoTimer + 812 12 CoreFoundation 0x0000000112ca6ada __CFRunLoopDoTimers + 243 13 CoreFoundation 0x0000000112ca12e4 __CFRunLoopRun + 2064 14 CoreFoundation 0x0000000112ca06f7 CFRunLoopRunSpecific + 560 15 GraphicsServices 0x0000000113a4728a GSEventRunModal + 139 16 UIKitCore 0x00000001255f362b -[UIApplication _run] + 994 17 UIKitCore 0x00000001255f8547 UIApplicationMain + 123 18 CastVideos-swift 0x0000000104d30fdf main + 63 Message from debugger: Terminated due to signal 6 19 dyld 0x000000010d9ac2bf start_sim + 10 20 ??? 0x0000000205638310 0x0 + 8680342288 )

    Which version of the Cast SDK are you using? - I am using Cast SDK for iOS ver 4.7.0 (the latest one) On which version(s) of the OS (iOS, Android) do you observe the problem? - iOS 16.1 at least On which device type(s) such as phones, tablets or laptops (iPad, iPhone, etc.) do you observe the problem? iPhone, iPad Do you observe the problem when running on a physical device, or the simulator, or both? both

    opened by soj 0
  • Error after input PIN in GuestMode

    Error after input PIN in GuestMode

    I implemented and use chromecast almost OK. But when I tried to cast on chrome cast 3 by Guest Mode, I acidently got this error.

    [0]: -[GCKClientCertificate importPKCS12:withPassword:] Failed to import the PKCS12 Identity

    does any one know why and how to fix it ?

    opened by rs-hungnl 1
Owner
Google Cast
Samples for Google Cast SDKs. Please only file issues for samples and direct SDK issues and questions to: https://developers.google.com/cast/support.
Google Cast
A lightweight app to play videos from the Files app in a better (dark) interface which avoids losing your playback position.

Playerly Playerly is a very lightweight Swift app that allows you to select a file (video or movie) from the built in Document Browser, and play it in

Julian Schiavo 28 Dec 3, 2022
Catalyst example of a grid-based video app that opens videos in secondary windows

Simple Catalyst example (Mac idiom) of a grid-based app populated with videos. On macOS, double-clicking a video opens it in a new playback window. Keyboard navigation is fully supported via the UIKit Focus Engine.

Steven Troughton-Smith 19 Dec 8, 2022
Swift library for embedding and controlling YouTube videos in your iOS applications via WKWebView!

YouTubePlayer Embed and control YouTube videos in your iOS applications! Neato, right? Let's see how it works. 0.7.0 Update: WKWebView breaking change

Giles Van Gruisen 825 Jan 3, 2023
Loop videos on iOS and Android (assuming only one video like on YouTube)

Mobile Video Loop By: Andrew-Chen-Wang iOS Safari Extension (soon Android) that lets you loop a video on your current website. This only works for the

Andrew Chen Wang 0 Dec 19, 2021
YouTubePlayerKit A Swift Package to easily play YouTube videos 📺

A Swift Package to easily play YouTube videos ??

Sven Tiigi 304 Jan 7, 2023
reward the user for watching videos to get coins then use them to get rid of annoying admob ads

reward the users for watching youtube videos to the end to earn coins, then use them to get rid of annoying admob ads like banners, interstitial & reward videos

Belal Samy 4 Nov 19, 2021
ABMediaView can display images, videos, as well as now GIFs and Audio!

Media view which subclasses UIImageView, and can display & load images, videos, GIFs, and audio and from the web, and has functionality to minimize from fullscreen, as well as show GIF previews for videos.

Andrew Boryk 80 Dec 20, 2022
Manga, anime, shows & movies tracker

Lists Manga, anime, shows & movies tracker Here is a preivew for the app edit: added top anime and manga recommendation using Jikan API

null 7 Oct 28, 2021
A fully functional short video app project.Record a six secends video while playing prank sounds.

prankPro A fully functional short video app project How to Install 1. use coconapod to init your xcode environment. 2. change the app-keys in `applica

huijimuhe 258 Jun 19, 2022
YoutubeKit is a video player that fully supports Youtube IFrame API and YoutubeDataAPI for easily create a Youtube app

YoutubeKit YoutubeKit is a video player that fully supports Youtube IFrame API and YoutubeDataAPI to easily create Youtube applications. Important Ref

Ryo Ishikawa 555 Dec 28, 2022
Valorem-demo - Demonstration code and video of Valorem, a bespoke portfolio recommendation platform to be created as an iOS mobile app.

valorem-demo Demonstration code of Valorem, a bespoke portfolio recommendation platform to be created as an iOS mobile app. The included code demonstr

Marcus Deans 1 Mar 4, 2022
Nextcloud Talk is a fully on-premises audio/video and chat communication service

Nextcloud Talk iOS app Video & audio calls and chat through Nextcloud on iOS Nextcloud Talk is a fully on-premises audio/video and chat communication

Nextcloud 112 Dec 26, 2022
How to Display Video from URL inside custom design UIView

Technicalisto How to Display Video from URL inside custom design UIView Add your UIView and connect it . Add This method for display func DisplayVideo

Aya Baghdadi 1 Jun 24, 2022
Audio player demo based on Swift and SwiftUI, which can play local or network audio.

SwiftAudioDemo Audio player demo based on Swift and SwiftUI, which can play local or network audio. In this demo, I have made a radio player to play n

Jensen Zhang 6 Mar 13, 2022
Contains a demo version of the official Roll player.

RollDemo This package is a demo version of Roll player which is a native iOS audiovisual player that builds on AVFoundation. Contact Information: Raji

Rajiv 8 Jul 29, 2022
▶️ video player in Swift, simple way to play and stream media on iOS/tvOS

Player Player is a simple iOS video player library written in Swift. Looking for an obj-c video player? Check out PBJVideoPlayer (obj-c). Looking for

patrick piemonte 2k Jan 2, 2023
The best way to watch Put.io on iPhone and iPad

The best way to watch Put.io on iPhone and iPad

Fetch 89 Oct 27, 2022
Easy way to show SRT files on AVPlayerViewController

    AVPlayerViewController-Subtitles is a library to display subtitles on iOS. It's built as a Swift extension and it's very easy to integrate. How To

Marc Hervera 216 Dec 23, 2022
Easy way to show SRT files on MPMoviePlayerController

    MPMoviePlayerController-Subtitles is a library to display subtitles on iOS. It's built as a Swift extension and it's very easy to integrate. How T

Marc Hervera 186 May 27, 2022