[Solution 1] 소켓 통신을 활용하여 유튜브 동영상 제어하기

이정연·2023년 5월 2일
0

Project

목록 보기
3/11
post-thumbnail

제스처 인식부에서 판단한 반환값을 통하여 유튜브를 제어하는 것이 목표다.

예를 들어, 1: 정지 2: 재생으로 약속하였다면

1과 2라는 정수를 플래그로 하여 동영상을 멈출지 재생할지를 결정한다.

class NetworkThread extends Thread{
    @Overide
    public void run() {
        try{
            Socket socket;
            socket = new Socket("{My IP}",8080);

            while (true){
                InputStream input = socket.getInputStream();
                DataInputStream dis = new DataInputStream(input);
                int data1 = dis.readInt();
                real_data = data1 / 16777216;

                if (real_data == 1){
                    videoView.pause();
                }
                else if (real_data == 2){
                    videoView.start();
                }
                else if (real_data == 3){
                    videoView.pause();
                    playerPosition = videoView.getCurrentPosition() - 10000;
                    videoView.seekTo(playerPosition);
                    videoView.start();
                }
                else if (real_data == 4){
                    videoView.pause();
                    playerPosition = videoView.getCurrentPosition() + 10000;
                    videoView.seekTo(playerPosition);
                    videoView.start();
                }
                else if (real_data == 99){
                    socket.close();
                    break;
                }
            }

        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
}
  • IP와 Port를 지정해 새로운 소켓 객체를 만든다
  • InputStream을 받아와 DataInputStream을 변환한다.
  • DataInputStream을 int 형으로 받는다.
  • 1: 정지, 2: 재생, 3: -10초, 4: +10초

카메라와 동영상이 동시에 재생되고 있는 화면이다.

제스처를 입력하면 제스처 인식부에서 이를 판단하고 약속한 반환값을 명령어 적용부로 보낸다.

명령어 적용부는 위의 코드에 따라 동영상을 제어하게 된다.

profile
0x68656C6C6F21

0개의 댓글