项目作者: KaustubhPatange

项目描述 :
The sample demonstrates the casting of local media files to Chromecast using cast SDK
高级语言: Java
项目地址: git://github.com/KaustubhPatange/Android-Cast-Local-Sample.git
创建时间: 2020-07-28T10:53:59Z
项目社区:https://github.com/KaustubhPatange/Android-Cast-Local-Sample

开源协议:Apache License 2.0

下载


Android-Cast-Local-Sample

build

The sample showcase the usage of Cask-SDK to create an Android sender app which plays local device media files on chromecast enabled devices.

This sample demonstrates playing of a local media file along with a subtitle track on chromecast enabled device.

This sample is built on top of Google Cast Android sample for Android (which explain the way for casting remote files only). Hence it includes some code excerpt from it.

This sample uses a third-party module tinyhttpd which is used to start a local HTTP Server to serve external storage directory as the root folder of the server. Note: This module is updated to fit according to the sample purpose.

Anatomy

Sample’s directory structure,

  1. -- app
  2. -- tinyhttd (a third party module to create HTTP server written in Java)
  3. -- src (all cast-specific codes written in Kotlin)
  • App connects to a receiver device.
  • Starts an internal HTTP server on the device IP address.
  • Constructs a MediaInfo object with the url from the HTTP server along with a subtitle track.
  • Cast the created MediaInfo object to the receiver device.

Run the sample

We are using some files from a json file which was used in the official cast sample.

  • Download sample.mp4 and sample.vtt (subtitle) files. Make sure to rename the files as named. Alternatively you can use cURL.
  1. curl -L -o sample.mp4 https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/DesigningForGoogleCast.mp4
  2. curl -L -o sample.vtt https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/tracks/DesigningForGoogleCast-en.vtt
  • Push the files into the root storage of your device.
  1. adb push sample.mp4 /sdcard
  2. adb push sample.vtt /sdcard
  • Clone the sample and run the app using Android studio. You can also install this sample-debug-app.
  1. git clone https://github.com/KaustubhPatange/Android-Cast-Local-Sample.git

Using the code

If you are building your own sender app, instead of copying the whole tinyhttpd module you can add the following dependencies to your build.gradle files.

This dependencies will make SimpleWebServer class available for use.

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url 'https://jitpack.io' }
  5. }
  6. }
  1. dependencies {
  2. implementation 'com.github.KaustubhPatange:Android-Cast-Local-Sample:Tag'
  3. }

References

License

  1. Copyright 2020 Kaustubh Patange
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. https://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.