Chrome 投射无法播放投放的视频



我正在为IOS上的chrome cast开发一个应用程序。我的应用程序将执行的功能之一将是播放本地视频从你的设备。要做到这一点,我使用github上名为CocoaHttpServer的外部源。这个Http服务器允许我将文件上传到本地主机服务。为此,我使用以下代码启动服务器:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
        // Configure our logging framework.
    // To keep things simple and fast, we're just going to log to the Xcode console.
    [DDLog addLogger:[DDTTYLogger sharedInstance]];
    // Create server using our custom MyHTTPServer class
    httpServer = [[HTTPServer alloc] init];

    // Tell the server to broadcast its presence via Bonjour.
    // This allows browsers such as Safari to automatically discover our service.
    [httpServer setType:@"_http._tcp."];
    // Normally there's no need to run our server on any specific port.
    // Technologies like Bonjour allow clients to dynamically discover the server's port at runtime.
    // However, for easy testing you may want force a certain port so you can just hit the refresh button.
    // [httpServer setPort:12345];
    // Serve files from our embedded Web folder
    NSString *webPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Web"];
    DDLogInfo(@"Setting document root: %@", webPath);
    [httpServer setDocumentRoot:webPath];
    [self startServer];
    gblvb = [GlobalVariables singleobj];
    self.mediaControlChannel = [[GCKMediaControlChannel alloc] init];
    self.mediaControlChannel.delegate = self;
    [gblvb.deviceManager addChannel:self.mediaControlChannel];
    [self.mediaControlChannel requestStatus];
}

这段代码然后设置了我的http服务器,并指出它在web文件夹中查看,该文件夹导入到我的主包中,并包含我从google下载的测试视频用于测试目的(该视频google在他们的示例中使用流式传输到chrome cast通过web)。这段视频来自http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4。除此之外,代码还设置了一个新的媒体通道,以便chrome cast转换为…

接下来我有一个void函数startServer,它真正建立连接并发布服务器…

- (void)startServer
{
    // Start the server (and check for problems)
    NSError *error;
    if([httpServer start:&error])
    {
        DDLogInfo(@"Started HTTP Server on port %hu", [httpServer listeningPort]);
    }
    else
    {
        DDLogError(@"Error starting HTTP Server: %@", error);
    }
}

最后,下面的代码将路径设置为等于localhost url,并实际将视频转换为chrome cast:

-(void)viewDidAppear:(BOOL)animated
{
path = [NSString stringWithFormat:@"localhost:%hu%@%@", [httpServer listeningPort], @"/", @"BigBuckBunny.mp4"];

    // Do any additional setup after loading the view from its nib.
    gblvb = [ GlobalVariables singleobj];

    deviceScanner = [[GCKDeviceScanner alloc] init];

    [deviceScanner addListener:self];
    [deviceScanner startScan];
    NSString *image;
    NSString *type;
    GCKMediaMetadata *metadata = [[GCKMediaMetadata alloc] init];

        image = @"Folder-Video-icon.png";
        [metadata setString:@"The MP4 file format defined some extensions over the ISO Base Media File Format to support MPEG-4 visual/audio codecs and various MPEG-4 Systems features such as object descriptors and scene descriptions."
                     forKey:kGCKMetadataKeySubtitle];
        type = @"video/mp4";
[metadata setString:[NSString stringWithFormat:@"%@%@", @"Casting " , gblvb.FileType]forKey:kGCKMetadataKeyTitle];

    [metadata addImage:[[GCKImage alloc]
                        initWithURL:[[NSURL alloc] initWithString:image]
                        width:480
                        height:360]];
    //define Media information
    sleep(2);
    GCKMediaInformation *mediaInformation =
    [[GCKMediaInformation alloc] initWithContentID:path
                                        streamType:GCKMediaStreamTypeNone
                                       contentType:type
                                          metadata:metadata
                                    streamDuration:0
                                        customData:nil];
    //cast video
    [_mediaControlChannel loadMedia:mediaInformation autoplay:TRUE playPosition:0];
    NSLog(@"Full Path : %@", path);
}

现在我的问题是,当这个http服务器发布并准备铸造的铬铸不发挥它,即使当我实际上导航到safari的路径视频显示完美。除此之外,我知道chrome cast流很好,因为它流谷歌在线示例视频很好。

编辑这是我在chrome上的调试日志:

Failed to load resource: the server responded with a status of 404 (Not Found) https://www.gstatic.com/eureka/player/undefined
 [  0.259s] [goog.net.WebSocket] Opening the WebSocket on ws://localhost:8008/v2/ipc
 cast_receiver.js:18
 [  0.580s] [goog.net.WebSocket] WebSocket opened on ws://localhost:8008/v2/ipc
 cast_receiver.js:18
GET https://www.gstatic.com/eureka/player/Folder-Video-icon.png 404 (Not Found) player.js:31
The page at 'https://www.gstatic.com/eureka/player/player.html?skin' was loaded over HTTPS, but displayed insecure content from 'http://localhost:49598/BigBuckBunny.mp4': this content should also be loaded over HTTPS.
 cast_receiver.js:69
GET http://localhost:49598/BigBuckBunny.mp4  cast_receiver.js:69
 [ 21.834s] [cast.receiver.MediaManager] Load metadata error
 cast_receiver.js:18
GET https://www.gstatic.com/eureka/player/Folder-Video-icon.png 404 (Not Found) 

我在模拟器上编写了一个函数来获取当前设备的IP地址,其中localhost部分在这一行path = [NSString stringWithFormat:@"localhost:%hu%@%@", [httpServer listeningPort], @"/", @"BigBuckBunny.mp4"];内,将其替换为设备的IP地址。

相关内容

  • 没有找到相关文章

最新更新