Languages

Menu
Sites
Language
watch face에서의 터치 이벤트와 이미지 교체, 사운드 출력 방법

gear s2 watch face를 css와 js로 제작 중입니다. 

기본 영역을 <div id="body-bg"> 로 정의하고, style.css에서 background-image: url('../image/bg1.png');로 기본 배경 이미지를 지정해 둔 상태입니다. 

 

목표는 특정 영역 혹은 시계 아무곳이나 터치를 하면 다른 이미지로 배경을 교체하며 사운드를 출력하는 것입니다. 

 

기본 js 파일 상단에서 

var bgDiv = document.querySelector("body-bg");

로 div 영역을 가져오고, 이벤트를 아래와 같이 바인딩 해보았습니다.

        document.addEventListener("click", function() {

             bgDiv.style.background = "url('image/bg2.png')";

        });

하지만 이미지가 변경되지 않는 상태이며, click 이벤트가 발생하지 않는 듯 합니다.

그리고 Audio()로 사운드 객체를 지정하고 audio.play();로 이벤트 발생 했을 때 소리가 나는지 확인해 보았지만 사운드 또한 플레이 되지않았습니다. 

사운드의 경우, GearWatchDesigner의 액션 항목을 보니 포함되어 있지 않은 걸로 봐서, watch face에서는 아예 사운드를 지원하지 않는 것일 듯 예상됩니다만, 같이 문의 드립니다. 

 

혹 이런 작동에 대한 샘플 코드가 있는 곳이 있다면 같이 추천 부탁드리겠습니다. 

 

 

gear s2 프로그래밍은 구글신으로도 검색이 거의 안되네요. 의지할 곳이 여기 밖에 없는지... ㅠ_ㅜ

 

View Selected Answer

Responses

3 Replies
JIHyun LEE

var bgDiv = document.querySelector("body-bg"); 를 document.getElementById 로 대체.

이후 이미지 교체에 대한 문제는 정상적으로 처리됨. 

 

watch face 에서는 사운드 지원되지 않는 듯.

Nafisul Islam Kiron

Hello, I am not sure what you have asked, translators are not very helpful.

What I have understood is that you want to change an image and play a sound on tap, is this correct?

 

And in your last comment you said something about getting html element. is it correct?

If that is the case then I use "getElementById" to get html elements, then I can change source and make other changes.

 

*Please post in English.

Mark as answer
JIHyun LEE

Right. I had  two problems how to change background image and play sound.

Now, I solved these problems. 

 

We can change background image by "getElementById("id").style.background ... " in javascript.

In case sound problem, 

at first, add audio tag in html file as below.

        <audio id="testAudio">

        <source src="sound/test.mp3" type="audio/mp3">

        </audio>     

 

and next, play that sound as below in javascript.

.

.

var snd0 = document.getElementById("testAudio");

snd0.play();

.

.

It works well. 

I hope this is helpful for you.