2013-08-15 3 views
1

ChromeCast API에 맞춤 명령을 추가 한 사람이 있습니까? TicTacToe 예제를 내 개발자 ID와 수정 된 프로토콜 문자열 (클라이언트와 서버 모두에서 변경됨)을 사용하여 성공적으로 얻었습니다. 안드로이드 측면에서 Chromecast 맞춤 명령이 작동하지 않음

, 나는이 작동 명령을 "결합"기존 있고, 나는 새로운 "이미지"명령을 추가하고 : 나는 조인 명령을 호출하는 경우

public final void join(String name) { 
    try { 
     Log.d(TAG, "join: " + name); 
     JSONObject payload = new JSONObject(); 
     payload.put(KEY_COMMAND, KEY_JOIN); 
     payload.put(KEY_NAME, name); 
     sendMessage(payload); 
    } catch (JSONException e) { 
     Log.e(TAG, "Cannot create object to join a game", e); 
    } catch (IOException e) { 
     Log.e(TAG, "Unable to send a join message", e); 
    } catch (IllegalStateException e) { 
     Log.e(TAG, "Message Stream is not attached", e); 
    } 
} 

public final void sendImage(String sURL) { 
    try { 
     Log.d(TAG, "sendImage"); 
     JSONObject payload = new JSONObject(); 
     payload.put(KEY_COMMAND, KEY_IMAGE); 
     payload.put(KEY_URL, sURL); 
     sendMessage(payload); 
    } catch (JSONException e) { 
     Log.e(TAG, "Cannot create object to send image", e); 
    } catch (IOException e) { 
     Log.e(TAG, "Unable to send an image message", e); 
    } catch (IllegalStateException e) { 
     Log.e(TAG, "Message Stream is not attached", e); 
    } 
} 

, 그것을 잘 작동 및 I 브라우저의 콘솔을 통해 기록 된 메시지를 볼 수 있습니다.

이 : 나는 인 sendImage 함수를 호출한다면, 나는 다음과 같은 오류 얻을 "onEnded 채널을 연결하는 데 실패했습니다 : 프로토콜 오류"유효한 명령이 수신 될 때 Chromecast의 측면에서

, 내가 볼 수 있습니다. 이 함수는 join 명령을 보낼 때 호출되지만 사용자 정의 "image"명령을 보낼 때는 호출되지 않습니다.

/** 
* Message received event; determines event message and command, and 
* choose function to call based on them. 
* @param {event} event the event to be processed. 
*/ 
onMessage: function(event) { 
    console.log('***== pre onMessage ==***'); 
    var message = event.message; 
    var channel = event.target; 
    console.log('********onMessage********' + JSON.stringify(message)); 
    console.log('mPlayer1: ' + this.mPlayer1); 
    console.log('mPlayer2: ' + this.mPlayer2); 

    if (message.command == 'join') { 
    this.onJoin(channel, message); 
    } else if (message.command == 'leave') { 
    this.onLeave(channel); 
    } else if (message.command == 'move') { 
    this.onMove(channel, message); 
    } else if (message.command == 'queue_layout_request') { 
    this.onQueueLayoutRequest(channel); 
    } else if (message.command == 'image') { 
    this.onImage(channel, message); 
    } else if (message.command == 'video') { 
    this.onVideo(channel, message); 
    } else if (message.command == 'song') { 
    this.onSong(channel, message); 
    } else { 
    cast.log.error('Invalid message command: ' + message.command); 
    } 
}, 

아이디어가 있으십니까? 내 사용자 정의 명령을 정의해야하는 곳이 있습니까?

편집 : 일반적으로 수신기에서 자바 스크립트 오류가 발생했습니다 의미

/** 
* Image event: display an image 
* @param {cast.receiver.channel} channel the source of the move, which 
*  determines the player. 
* @param {Object|string} message contains the URL of the image 
*/ 
onImage: function(channel, message) { 
    console.log('****onImage: ' + JSON.stringify(message)); 

    //Hide video and show image 
    mVideo.style.visibility='hidden'; 
    mImage.style.visibility='visible'; 
    mImage.src = message.url; 

}, 

답변

1

: 또한 onImage 프로토 타입을 표시합니다. ChromeCast 기기의 IP 주소로 포트 9222에서 Chrome을 열고 Chrome 개발자 도구를 사용하여 문제를 디버깅합니다.

메시지 처리기의 수신기 프로토 타입에 "onImage"라는 새 함수를 선언 했습니까?

+0

예, 저는 크롬 개발자 도구를보고 조인 명령을받을 때 콘솔 메시지를 봅니다. 원래 자바 스크립트 오류가 발생했을 때 콘솔에 표시됩니다. 하지만 이제는 이미지 명령을 보낼 때 새 줄이 표시되지 않습니다. 자바 스크립트만큼 멀지 않은 것 같습니다. 그리고 위의 코드는 수신기 프로토 타입을 추가 한 곳입니다. 다른 곳이 있습니까? –

+0

ChromeCast 기기를 다시 시작하는 것이 좋습니다. 때로는 이전 버전의 수신기를 캐싱하는 것처럼 보입니다. 또한 어떤 이유로 리시버가 닫히는 경우를 대비하여 개발자 도구 설정에서 '로그 기록시 보존'을 사용 설정합니다. –

+0

자바 스크립트 코드를 변경할 때마다 ChromeCast 기기를 다시 시작했지만 도움이되지 않았습니다. 그러나 몇 시간 후 돌아와서 이제 ChromeCast에서 실제로 처리되는 '이미지'명령이 표시됩니다. 어쩌면 Google 서버에서 캐싱이 발생했을 것입니까? ChromeCast 기기가 내 웹 서버에서 직접 가져 왔다고 생각했지만 어쩌면 아닙니다. 도와 주셔서 감사합니다! –