StratoSphere Stream


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  Date date = new Date();
    long dateLongTime = date.getTime();
    //Date함수를 사용한 long time 구하기
    System.out.println(dateLongTime);
 
    //System을 사용한 long time 구하기
    long dateLongTime2 = System.currentTimeMillis();
    System.out.println(dateLongTime2);
 
    //Calander함수를 이용한
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd",Locale.KOREA);
    // 날자를 set 하는 방법 (달은 0에서 시작한다)
    cal.set(2000,0,1);
    //SimpleDateFormat을 사용한 날짜 String
    System.out.println("현재날자 : " +sdf.format(cal.getTime()));
 
    //년월일 구하는 방법
    System.out.println("년 : " +cal.get(Calendar.YEAR));
    System.out.println("월 : " +cal.get(Calendar.MONTH));
    System.out.println("일 : " +cal.get(Calendar.DATE));
    System.out.println("요일여부 : " +cal.get(Calendar.DAY_OF_WEEK)); //1: 일요일 , 2: 월요일.. 7: 토요일
    System.out.println("WEEK_OF_YEAR : " +cal.get(Calendar.WEEK_OF_YEAR));// 몇째주 주인가?
    //2000년의 2월의 마지막 날은? => 29일
    System.out.println ("월의 마지막 일자 : " + cal.getActualMaximum ( Calendar.DATE ) );
 
    //1년에 전체 요일과 일요일과 토요일이 그리고 토요일과일요일을은 몇개?
    int allDay = 0;
    int allDayHoliday = 0;
    int allDaySun = 0;
    int allDaySat = 0;
 
    for(int i = 0; i< 12 ; i++){
      cal.set(2000,i,1); //초기 날짜 받음
      int x = cal.getActualMaximum ( Calendar.DATE ); //달의 마지막 날자를 다름 for에서 length로 수정
 
      for(int j = 1; j<= x ; j++){
        cal.set(2000,i,j); //day를 수정해줌
 
        int temp = cal.get(Calendar.DAY_OF_WEEK);
        System.out.println("temp: " + temp);
        if(temp == 1 ){
          allDayHoliday++;
          allDaySun++;
        }
        if(temp == 7 ){
          allDayHoliday++;
          allDaySat++;
        }
        allDay++;
      }
 
    }
    System.out.println("전체: " + allDay); //2000년은 윤년이 있어서 366일이다.
    System.out.println("전체토일: " + allDayHoliday); // 106
    System.out.println("일요일: " + allDaySun); //53
    System.out.println("토요일: " + allDaySat); // 53
cs


'프로그래밍 > JAVA' 카테고리의 다른 글

[자바] Date 함수와 Calender 함수  (0) 2018.10.15

Comment : 0

1. 메니페스토에 인터넷


2. 


package location.techdown.com.simplevideoplayer;

import android.media.AudioManager;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.VideoView;

import java.net.URL;

public class MainActivity extends AppCompatActivity {
Button play;
Button stop;
VideoView videoView;
SeekBar seekBar;
AudioManager maudioManager = null;
TextView textView;

String url = "http://techslides.com/demos/sample-videos/small.mp4";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

play = findViewById(R.id.play);
stop = findViewById(R.id.stop);
videoView = findViewById(R.id.videoView);
seekBar = findViewById(R.id.seekBar);
textView = findViewById(R.id.textView);

//음량값 받기
maudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
int maxVol = maudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
//최대치 값을 가져와서 seekBar Max로 하기
seekBar.setMax(maxVol);
textView.setText("음량최대값: "+ maxVol);


//Seekbar로 음량 변경
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
textView.setText("변환값 "+ i);
//음악 음량 변경
maudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, i, AudioManager.FLAG_SHOW_UI);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});

MediaController mediaController = new MediaController(this);
videoView.setMediaController(mediaController);
//주소변경
videoView.setVideoURI(Uri.parse(url));
videoView.requestFocus();

play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//플레이
videoView.start();
}
});

stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//멈춤
videoView.stopPlayback();
}
});

}
}


응용판으로 Seekbar을 이용해서 음량을 조절할 수 있게 했다.

Comment : 0

1. 메니페스트에 인터넷 권한 승인하기


2. 

package location.techdown.com.sampleaudioplayer;

import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.io.IOException;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

Button play;
Button stop;
Button replay;
TextView textView;

static final String bgm = "http://mini-files.thinkpool.com/files/mini/2004/09/14/%EC%BD%94%EC%9A%94%ED%83%9C-%EB%B6%88%EA%BD%83.mp3";
private MediaPlayer mediaPlayer;
private int playbackPosition = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

play = findViewById(R.id.button);
stop = findViewById(R.id.button2);
replay = findViewById(R.id.button3);
textView = findViewById(R.id.textView);

play.setOnClickListener(this);
stop.setOnClickListener(this);
replay.setOnClickListener(this);


}

@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.button: //play
playAudio(bgm);
Toast.makeText(getApplicationContext(), "재생", Toast.LENGTH_LONG).show();
break;
case R.id.button2: //stop
if (mediaPlayer != null) {
//현재 위치 받기
playbackPosition = mediaPlayer.getCurrentPosition();
mediaPlayer.pause(); //멈춤
Toast.makeText(getApplicationContext(), "일시중지", Toast.LENGTH_LONG).show();
textView.setText("현재위치 : "+playbackPosition);
}
break;
case R.id.button3: //replay
//재생이 있고 재생중이 맞다면 실행
if (mediaPlayer != null && mediaPlayer.isPlaying() == false) {
//재시작을 하면 시작후 seekTo로 중단되었던 포지션으로 이동
mediaPlayer.start(); //시작
mediaPlayer.seekTo(playbackPosition); // 타임 위치로 가기

}
break;

}
}

@Override
protected void onDestroy() {
super.onDestroy();
killAudio();
}

public void playAudio(String url) {
killAudio();
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(url); // 주소 받기
mediaPlayer.prepare(); // 준비
mediaPlayer.start(); //시작
} catch (IOException e) {
e.printStackTrace();
}

}

private void killAudio() {
if (mediaPlayer != null) {
//리소스 해제
mediaPlayer.release();
}
}
}


Comment : 0