분명히 디자인 화면에서는 보이는데 실제 디바이스에서 실행시켜보면 보이질 않네요..
thumb만 보이고 seekbar는 안보이는 이상한 현상이 나타납니다.. 근데 이유를 모르겠네요..
<MainActivity>
public class MainActivity extends AppCompatActivity {
MediaPlayer mp;
int pos;
private Button bStart;
SeekBar sb;
boolean isPlaying = false;
class MyThread extends Thread {
@Override
public void run(){
while(isPlaying){
sb.setProgress(mp.getCurrentPosition());
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sb = (SeekBar) findViewById(R.id.seekBar1);
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(seekBar.getMax() == progress){
bStart.setVisibility(View.VISIBLE);
isPlaying = false;
mp.stop();
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
isPlaying = false;
mp.pause();
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
isPlaying = true;
int ttt = seekBar.getProgress();
mp.seekTo(ttt);
mp.start();
new MyThread().start();
}
});
bStart = (Button) findViewById(R.id.button1);
bStart.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
mp = MediaPlayer.create(getApplicationContext(), R.raw.flower);
mp.setLooping(false);
mp.start();
int a = mp.getDuration();
sb.setMax(a);
new MyThread().start();
isPlaying = true;
bStart.setVisibility(View.INVISIBLE);
}
});
}
@Override
protected void onPause(){
super.onPause();
isPlaying = false;
if(mp != null){
mp.release();
}
bStart.setVisibility(View.VISIBLE);
}
}
<activity_main>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/activity_main"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="speakeragent.com.testagentplayer.MainActivity">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="MediaPlayer 활용"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:text="시작" />
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="18dp"
android:progressDrawable="@drawable/seekbar_seekbar1"
android:thumb="@drawable/seekbar_thumb1"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:thumbOffset="0dp"
/>
</RelativeLayout>
<seekbar_seekbar1>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape android:shape="line">
<stroke android:width="6dp" android:color="#D5D5D5" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape android:shape="line">
<stroke android:width="6dp" android:color="#B2CCFF"/>
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape android:shape="line">
<stroke android:width="6dp" android:color="#6799FF"/>
</shape>
</clip>
</item>
</layer-list>
<seekbar_thumb1>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#B2CCFF"></solid>
<stroke android:width="2dp"
android:color="#B2CCFF"/>
<size
android:width="6dp"
android:height="6dp"/>
</shape>
한 가지 이상한점은 activity_main파일에서 아래의 코드를 없애면 seekbar가 보입니다.
android:thumb="@drawable/seekbar_thumb1"
문제가 뭔지.. 잘 모르겠네요..