actions-on-google / actions-on-google-java

Java/Kotlin library for Actions on Google
Apache License 2.0
286 stars 39 forks source link

Not able play video from hls direact link into chromecast using google smart home action #51

Closed amiya-elear closed 4 years ago

amiya-elear commented 4 years ago

I am using google action sample code for camera stream to Chromecast Here is my code

public class MySmartHomeApp extends SmartHomeApp {

private static final Logger LOGGER = LoggerFactory.getLogger(MySmartHomeApp.class);

@NotNull @override public SyncResponse onSync(@NotNull SyncRequest syncRequest, @nullable Map headers) { SyncResponse.Payload payload = new SyncResponse.Payload(); payload.setAgentUserId("1836.15267389"); payload.setDevices( new SyncResponse.Payload.Device[] { new SyncResponse.Payload.Device.Builder() .setId("5e0f5d1820a57b00113d7a7c") .setType("action.devices.types.CAMERA") .addTrait("action.devices.traits.CameraStream") .setName( Collections.singletonList("Sirius Corporation 3000"), "living room camera", Collections.singletonList("Camera")) .setWillReportState(false) .setAttributes( new JSONObject() .put("cameraStreamSupportedProtocols", new String[] {"hls"}) //.put("cameraStreamNeedAuthToken", true) // .put("cameraStreamNeedDrmEncryption", true) ) .setDeviceInfo("blinds manufacturer", "xyz", "3.2", "11.4") .build() }); return new SyncResponse(syncRequest.getRequestId(), payload); }

@NotNull @override public ExecuteResponse onExecute( @NotNull ExecuteRequest executeRequest, @nullable Map map) { ExecuteResponse.Payload payload = new ExecuteResponse.Payload(); payload.setCommands( new ExecuteResponse.Payload.Commands[] { new ExecuteResponse.Payload.Commands( new String[] {"5e0f5d1820a57b00113d7a7c"}, "SUCCESS", new HashMap<String, Object>() { { put("cameraStreamAccessUrl", "https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8"); //put("cameraStreamReceiverAppId", "1g2f89213hg"); //put("cameraStreamAuthToken", "12657342190192783"); } }, null, null) }); return new ExecuteResponse(executeRequest.getRequestId(), payload); }

@NotNull @override public void onDisconnect(DisconnectRequest disconnectRequest, Map headers) { String token = (String) headers.get("authorization");

} }

using this code I am able to sync my camera device to google home app and I am able to send a command to the camera to stream data from HLS URL to my Chromecast device show living room camera to my bedroom tv(Chromecast)

In my application log, I am able to see that execute command starting the stream. issue: I am not able to see the stream on TV it's displaying "smart home camera" not able to view the stream. am I missing something in my code to make HLS direct link to compatible with Chromecast? or what is the issue ?

I will be glad if I get some solution to make it work

Application Log 145 [main] INFO XXXX.Server - server started... 88228 [Thread-2] INFO XXXX.Serverr$XXXXHandler - Serving the request with request methodPOST 88229 [Thread-2] INFO XXXX.ServerXXXXHandler - POST request process starts here... 88315 [Thread-2] INFO XXXX.Server$XXXXHandler - Body Input:{"inputs":[{"context":{"locale_country":"US","locale_language":"en"},"intent":"action.devices.EXECUTE","payload":{"commands":[{"devices":[{"id":"5e0f5d1820a57b00113d7a7c"}],"execution":[{"command":"action.devices.commands.GetCameraStream","params":{"StreamToChromecast":true,"SupportedStreamProtocols":["progressive_mp4","hls","dash","smooth_stream"]}}]}]}}],"requestId":"16858408752476564434"} 89230 [Thread-2] INFO XXXX.Server$XXXXHandler - {"payload":{"commands":[{"ids":["5e0f5d1820a57b00113d7a7c"],"status":"SUCCESS","states":{"cameraStreamAccessUrl":"https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8"}}]},"requestId":"16858408752476564434"}