When Google introduced its Chromecast streaming stick in the late summer 2013, this radically different from other HDMI streaming solutions on the market differed: Instead of established protocols like DLNA or UPnP, Google put on a controls robbed the browser, pushing a push Channel for the transfer of commands. On a remote, Google renounced first. This role should take an Android or iOS tablet or smartphone.
No streaming in the classical sense
In the first few weeks, Chromecast was limited to Google's own services of Play Movies, Play Music and Youtube, and finally other web services were added. Since the release of the SDK for iOS, Android and the Chrome browser, it is also possible to stream videos that are provided in the local network via HTTP. These are ideal prerequisites for your own hacks, for example, to send music or videos from a NAS or a Raspberry Pi to Chromecast.
Easy start in Chrome browser
Chromecast is similar to UPnP and DLNA, with up to three parties involved: Chromecast itself is the media (media renderer), tablet, smartphone or a PC with a Chrome browser serve as a remote control point A web server delivers the data. From the smartphone to Chromecast, only control information such as the URL of the movie you are playing or the pause command is transferred. This has several advantages.
Still a lot to do
The biggest is that, for example, a very weak smartphone does not have to send via WLAN all the time, which also keeps the network clutter low - in scenarios where a smartphone sends, the video must first take the WLAN path to the accesspoint, which sends it to streaming -Adapter.
Combined with local player
In terms of media sources, Chromecast is very modest: if you do not want to transcode on the fly, a web server that allows jumping to any position of large files - Apache and Lighttpd support this and do not overburden a Raspberry Pi. As media formats, Chromecast primarily supports MP3 for audio, MP4 containers with H.264 video track and MP3 audio track, as well as Google's own codecs and Vorbis. Not officially supported, but are currently usable MKV containers.
If you want to get started with the software development for Chromecast, you should have some javascript knowledge - only Chrome with the Chromecast extension, an HTTP server and a good editor is necessary. You do not need to download an SDK or apply for a developer key. A tiny flaw in the development without key: You can not design the player with its own design - for example, a logo before a video is loaded.
Our example is based on an official demo of CastHelloVideo, but the javascript is radically excluded: Neither a display of thumbnails in the browser is provided, nor do we place emphasis on storing or loading a session. With such advanced methods, it is possible to later terminate a streaming session on one device and resume it at another, without a video being stuck in between.
Tip: The author's GitHub repositories contain both the sample application presented here, as well as a more comprehensive version with local player
As an example, you should first download Big Buckbunny and Elephants Dream from Google's servers. This ensures that they run in both the Chrome browser and Chromecast. In addition to the two videos, only one HTML and one javascript file is needed. For CSS, a CSS file is useful. Pictures etc. can be added later. In the example, we're missing a local player in the HTML page. Instead, we link to the video - Chrome plays it in a new tab
In the script you can see that the most important controls are present - though as normal HTML-Formelelemente anything but nice. The two buttons Launch app and Stop app are used to connect the HTML app to Chromecast, or to disconnect it from it. Only when this connection is established, all other elements have a function.
Somewhat more extensive is the javascript, which is why we focus on the most important functions. First, the Cast API has to be initialized. Here we determine that the default receiver (player without own theming possibilities) is to be used and set the auto-join policy, which determines when a chromecast is connected automatically.
Finally, the chrome.cast.initialize () function takes callback functions for the success and failure as second and third parameters. These callback functions have thinned to the absolute minimum, usually assigning only one variable or giving a message on the javascript console. You can later extend these callback functions to display meaningful errors or to hide and display certain controls
Function initializeCastApi () {var sessionRequest = new chrome.cast. SessionRequest (chrome.cast.media.DE FAULT_MEDIA_RECEIVER_APP_ID); var apiConfig = new chrome.cast. ApiConfig (sessionRequest, sessionListener, receiverListener, chrome.cast.AutoJoinPolicy.TAB_AND_ ORIGIN_SCOPED), chrome.cast.initialize (apiConfig, on InitSuccess, onError), console.log ("Cast API initialized")
Tip: Media Apps for Chromecast
The actual connection with the Chromecast is made with
Function launchApp () {console.log (, Launching app ... '); chrome.cast.requestSession (onRequest SessionSuccess, onError)
To play a video, it must first be loaded by Chromecast. For this purpose, we have defined a function loadMedia (), which gets passed a URL. Chromecast tries to load this URL and jumps to the beginning of the movie. In the callback function onMediaDiscovered () we make it easy and start playing the loaded movie directly.
The playMedia () function, triggered by the "Play" button, determines which radio button the user clicked on, and generates the URL of the video and calls loadMedia (). The basic functionality in the simplest form is
In addition to play (), the mediaSession object also provides pause (), resume (), and stop () functions that are easy to wire. In the case of pause / resume, we use a button to change the label. The volume setting is only slightly more complex: the API provides an object that takes a float value between 0 and 1 for the volume and a boolean for the mute.
Conclusion
Our example performs only a few plausibility checks and does not care to disable currently unavailable controls. In order to make the example more usable, you should first get an error message when it is called in another browser or in Chrome without a Chromeecast extension.
The next step should be to deactivate in the function initCast () the controls that are not usable at the beginning and activate them via callback when they are usable - for example, the Play and Stop app buttons are not active until the connection to the Chromecast is established Is. Similarly, active Pause and Stop buttons only make sense when a movie is playing.
Exciting is the display of a progress bar and the current location of the film. To do this, you must install timers that periodically read the updated mediaSession object and update the corresponding elements in the DOM tree.
Particularly attractive is the self-built streaming solution, if you combine it with a local player, but the control of an HTML5 video object is not part of this article. The second official example uses this connection: If you start a video, this is played first locally and after connection with a Chromecast on the TV. Just as easy, with a maximum of one second error, the Chromecast video to the Chrome browser is restored.
In view of the fact that the Chromecast itself gives every device in the network information on whether and what it is currently playing, very practical applications are possible with appropriate programming: you can choose a video via the smartphone and start viewing the Chromecast and TV.
If it's uncomfortable on the sofa and you want to finish the video on the notebook, start Chrome, connect to the Chromecast, and ask your app to ask if the existing session should be taken. After disconnecting the device, the TV can be turned off and the movie continues to run locally.
Although the possibility of using Chromecast with several control points is intended for the aforementioned scenario, it gives the creative programmer the possibility to implement a quiz via a custom receiver, which can be used by two people with the smartphone as a hot button.
It is conceivable that not only text is displayed as an explanation for the correct answers, but video and audio players are also used. Another application of the Javascript API is the control of films that implement the recently emerging second-screen format. It is conceivable that not only additional information can be displayed in the browser, but also interactively influence the action or change the perspective.
Some practical apps are compatible with Chromecast.
Google's Chromecast convinces with a tidy and easy-to-learn Javascript API. Anyone who has already gained initial experience with Responsive Webdesign will quickly be familiar with the API and can use the extensive sample programs to easily create player applications for their own home network or their own website.
From the initial closure to pure webstreaming is now nothing left - even if the rumor persists with many users, Chromecast would be an anti-development platform: The opposite is the case. It remains the only real shortcoming is the very clear codec equipment, which in many cases would require the transcoding of large parts of your own video collection, this should be displayed on your own TV via Browser Control Point.
Https://github.com/mschlenker/PC-Magazine;https://github.com/mschlenker/RollerCaster
The versatile Plex MediaCenter implements Chromecast support not only as an iOS and Android app but also via a browser. If you are looking for a ready-to-use media center solution for Linux servers or NAS, then you should take a look at the Android app Play to Chromecast streams various video services that do not yet provide native Googlecast support for the Chromecast.Localcast streams stored locally on the phone or tablet Photos and videos about the Chromecast. Attention: Because of constant WLAN activity a good network connection and a full battery is required.
No comments:
Post a Comment