안드로이드 개발 질문/답변
(글 수 45,052)
안녕하세요.
이미지 스위쳐를 이용해서 아래 그림과 유사하게 thumb을 스크롤하다가 클릭하면 하단에 큰 이미지가 나오게 구현 하였습니다.
여기에 특정 이미지가 선택되면 특정 mp3 파일을 아래 미디어 함수를 이용하여 반복 재생이 되게 구현을 한 상태입니다. (아래 그림과 같이)
구글 넥서스 폰에 올려서 잘 돌아 가는 것을 확인하였습니다.
그런데 HTC Hero 단말에 올렸는데.. 오동작을 하네요...
thumb가 4개(pic1, pic2, pic3, pic4)가 있고 음원이 4개(sound1, sound2, sound3, sound4)가 있을때,
pic1을 선택하면 sound1이 반복 재생 되어야 하는데.. sound1 재생이 완료되면 sound2로 넘어가고 같은 식으로 sound4까지 넘어 갑니다. (넥서스 원 단말에서는 정상 동작함)
아래와 같은 함수를 사용했는데... 안드로이드 플랫폼 버젼이 틀려서 인지..함수가 틀려서 인지 잘 모르겠습니다.
추가적인 질문으로 Portrait(세로보기) mode 만 지원하고 싶은데 어떻게 해야 하나요? 화면 lock 거는 기능이 있나요??
읽어 주셔서 감사합니다.
악플 보다 더 무서운 것이 무플입니다. ~~ㅠㅠ 답변 부탁드립니다.
/** Stop old song and start new one */
public static void play(Context context, int resource) {
stop(context);
mp = MediaPlayer.create(context, resource);
mp.setLooping(true);
mp.start();
}
/** Stop the music */
public static void stop(Context context) {
if (mp != null) {
mp.stop();
mp.release();
mp = null;
}
}
play.java source file ============================================================
package com.eureka.SmilingDog;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.Gallery.LayoutParams;
import android.widget.ViewSwitcher.ViewFactory;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
public class SmilePlay extends Activity implements ViewFactory{
//---the images to display---
Integer[] imageIDs = {
R.drawable.pic1,
R.drawable.pic2,
R.drawable.pic3,
R.drawable.pic4,
R.drawable.pic5,
};
private ImageSwitcher imageSwitcher;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.smileplay);
imageSwitcher = (ImageSwitcher) findViewById(R.id.switcher1);
imageSwitcher.setFactory(this);
imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_in));
imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out));
Gallery gallery = (Gallery) findViewById(R.id.gallery1);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView parent,
View v, int position, long id)
{
imageSwitcher.setImageResource(imageIDs[position]);
}
});
}
public View makeView()
{
ImageView imageView = new ImageView(this);
imageView.setBackgroundColor(0xFF000000);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setLayoutParams(new
ImageSwitcher.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
return imageView;
}
public class ImageAdapter extends BaseAdapter
{
private Context context;
private int itemBackground;
public ImageAdapter(Context c)
{
context = c;
//---setting the style---
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
itemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
//---returns the number of images---
public int getCount()
{
return imageIDs.length;
}
//---returns the ID of an item---
public Object getItem(int position)
{
return position;
}
public long getItemId(int position)
{
return position;
}
//---returns an ImageView view---
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView imageView = new ImageView(context);
imageView.setImageResource(imageIDs[position]);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setLayoutParams(new Gallery.LayoutParams(150, 120));
imageView.setBackgroundResource(itemBackground);
return imageView;
}
}
}