【问题标题】:Does my code is not correctly implementing google chromecast button and ability to stream?我的代码是否未正确实现 google chromecast 按钮和流式传输功能?
【发布时间】:2019-07-02 13:18:55
【问题描述】:

我已经实现了 google chrome cast 并以编程方式添加了按钮,但设备未显示按钮和流式传输功能。我的代码是不是写错了??

我已经尝试了这个指南https://dev.to/lawgimenez/implement-chromecast-on-ios-using-swift-4dd4,但我的按钮没有显示。

import UIKit
import AVKit
import QuickLook
import GoogleMobileAds
import GoogleCast

class MediaViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UIDocumentInteractionControllerDelegate, QLPreviewControllerDelegate, QLPreviewControllerDataSource,     GADInterstitialDelegate, GCKSessionManagerListener, GCKRequestDelegate {

@IBOutlet weak var bannerView: DFPBannerView!
@IBOutlet weak var mediaTableView: UITableView!
private var castButton: GCKUICastButton!

var interstitial: GADInterstitial!


override func viewDidLoad() {
    super.viewDidLoad()

    castButton = GCKUICastButton(frame: CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(24), height: CGFloat(24)))
    // Overwrite the UIAppearance theme in the AppDelegate.
    castButton.tintColor = UIColor.white
    navigationItem.rightBarButtonItem = UIBarButtonItem(customView: castButton)
}

这是我的 Appdelegate.swift

import UIKit
import CoreData
import AVFoundation
import GoogleCast

let themeColor = UIColor(red: 0.01, green: 0.41, blue: 0.22, alpha: 1.0)

let kPrefPreloadTime = "preload_time_sec"
let kPrefEnableAnalyticsLogging = "enable_analytics_logging"
let kPrefAppVersion = "app_version"
let kPrefSDKVersion = "sdk_version"
let kPrefEnableMediaNotifications = "enable_media_notifications"

let appDelegate = (UIApplication.shared.delegate as? AppDelegate)

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GCKLoggerDelegate {

let kReceiverAppID = "6D744F12"
fileprivate var enableSDKLogging = true
fileprivate var mediaNotificationsEnabled = false
fileprivate var firstUserDefaultsSync = false
fileprivate var useCastContainerViewController = false
let kDebugLoggingEnabled = true

var window: UIWindow?
var isCastControlBarsEnabled: Bool!

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {


    // Override point for customization after application launch.
    let criteria = GCKDiscoveryCriteria(applicationID: kReceiverAppID)
    let options = GCKCastOptions(discoveryCriteria: criteria)
    options.physicalVolumeButtonsWillControlDeviceVolume = true
    GCKCastContext.setSharedInstanceWith(options)

    // Enable logger.
    let logFilter = GCKLoggerFilter()
    logFilter.minimumLevel = .verbose
    GCKLogger.sharedInstance().filter = logFilter
    GCKLogger.sharedInstance().delegate = self

    // MARK - GCKLoggerDelegate

    func logMessage(_ message: String, at level: GCKLoggerLevel, fromFunction function: String, location: String) {
        if (kDebugLoggingEnabled) {
            // Send SDK's log messages directly to the console.
            print("\(location): \(function) - \(message)")

        }
    }

    return true
}

【问题讨论】:

  • 您是否在 Google Cast 开发者控制台中注册了您的投射设备?您是否将您的应用 ID 添加到源代码中?
  • @AshokPolu 当然,我已经注册并添加了应用程序到源代码
  • @AshokPolu 和我的问题一样,但我需要的只是能够使用最新版本的 SDK 无法正常工作(((
  • 您确定您的设备和 Chromecast 在同一个网络中吗?您还确定 Chromecast 已开启?

标签: ios swift chromecast


【解决方案1】:

我也在制作一个演员应用程序。我遇到了同样的事情,这对我有用。事实证明,您需要告诉导航打开。

// initiates the navigation bar to place the chrome icon
    titleView = navigationItem.titleView
    rootTitleView = UIImageView(image: UIImage(named: "logo_castvideos.png"))
    castButton = GCKUICastButton(frame: CGRect(x: CGFloat(0), y: CGFloat(0),
                                               width: CGFloat(24), height: CGFloat(24)))
  castButton.isHidden = false
    castButton.tintColor = UIColor.white
    self.setNavigationBar()
    NSObject.setAccessibilityLabel("true")

【讨论】:

    猜你喜欢
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    • 2011-09-27
    • 2016-02-27
    • 2014-03-27
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    相关资源
    最近更新 更多