안녕하세요

프로그램 과정에서 막혔던 문제들에 대한 해결책 정리


페이지 목록

레이블이 AUDIO인 게시물을 표시합니다. 모든 게시물 표시
레이블이 AUDIO인 게시물을 표시합니다. 모든 게시물 표시

2011년 2월 16일 수요일

[안드로이드] mediastore 내에서 select Query 사용 방법

Cursor cur1 = getContentResolver().query(
                           MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, cols, null, null,
                           null);

위 상태는 그냥 모든 data를 다 가져오는 것이다.

 내가 원하는 것은 이 중에서 내가 원하는 가수의 노래만을 뽑아오는 것이다.

그렇다.

이 방법이다.!!!!!

String where = "artist = '" + singer + "'";
             Cursor cur = getContentResolver().query(
                           MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, mCursorCols, where,
                           null, "artist ASC");

TIP) String 앞 뒤로 ‘ ‘ 을 붙여야지만 제대로 쿼리를 수행한다!

2011년 1월 20일 목요일

[안드로이드] sdcard/audio 에 있는 mp3 album_art를 가져와서 보여주는 소스(andorid show albumart using sdcard mp3)

package how.Album;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;

import android.app.ListActivity;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;

public class albumArt extends ListActivity {
    /** Called when the activity is first created. */
    private static final BitmapFactory.Options sBitmapOptionsCache = new BitmapFactory.Options();
    private static final Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
    Context mContext;
    ImageView image;
    FileManager fM;
    ArrayList<Bitmap> albumarts = new ArrayList<Bitmap>();
    ArrayList<String> albumInfo = new ArrayList<String>();
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mContext = this;
        fM = new FileManager();
        fM.initFiles(this);
        image = (ImageView)findViewById(R.id.row_album_art);
    
      
        String[] cols = new String[] {
                MediaStore.Audio.Albums._ID,
                MediaStore.Audio.Albums.ARTIST,
                MediaStore.Audio.Albums.ALBUM,
                MediaStore.Audio.Albums.ALBUM_ART
        };

        Cursor cur = getContentResolver().query(
                    MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
                    cols , null , null, null);
      
        if (cur.moveToFirst()) {
            String ablum;
            String artist;
            String id;
            String albumArt;
            int idNum;
            int artistColumn = cur.getColumnIndex(MediaStore.Audio.Albums.ARTIST);
            int ablumColumn = cur.getColumnIndex(MediaStore.Audio.Albums.ALBUM);
            int albumArtColumn = cur.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART);
            String imagePath;
      
            do {
                // Get the field values
             idNum = cur.getInt(0);         // 레코드의 _id를 가져옵니다.
             id = String.valueOf(idNum);
             artist = cur.getString(artistColumn);     // title 필드의 값을 가져옴
             ablum = cur.getString(ablumColumn);   // artist 필드의 값을 가져옴
             albumArt = cur.getString(albumArtColumn);
            
          
          
             Bitmap album_art = getBitmapImage( idNum,200, 200);
                albumarts.add(album_art);       // 두개 합쳐서  array list 에 넣어줌.
                albumInfo.add(ablum + " - " + artist);
              
            } while (cur.moveToNext());
            ArrayAdapter<String> songList = new ArrayAdapter<String>(this,
             android.R.layout.simple_list_item_1, albumInfo);
            setListAdapter(songList);
        }
      
      
    }

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
Bitmap b = albumarts.get(position );
image.setImageBitmap(b);

}
  
  public Bitmap getBitmapImage(int id, int w, int h) {
       ContentResolver res = mContext.getContentResolver();
             Uri uri = ContentUris.withAppendedId(sArtworkUri, id);
             if (uri != null) {
                 ParcelFileDescriptor fd = null;
                 try {
                     fd = res.openFileDescriptor(uri, "r");
                     int sampleSize = 1;
                   
                     sBitmapOptionsCache.inJustDecodeBounds = true;
                     BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor(), null, sBitmapOptionsCache);
                     int nextWidth = sBitmapOptionsCache.outWidth >> 1;
                     int nextHeight = sBitmapOptionsCache.outHeight >> 1;
                     while (nextWidth>w && nextHeight>h) {
                         sampleSize <<= 1;
                         nextWidth >>= 1;
                         nextHeight >>= 1;
                     }
                     sBitmapOptionsCache.inSampleSize = sampleSize;
                     sBitmapOptionsCache.inJustDecodeBounds = false;
                     Bitmap b = BitmapFactory.decodeFileDescriptor(
                             fd.getFileDescriptor(), null, sBitmapOptionsCache);
                     if (b != null) {
                         if (sBitmapOptionsCache.outWidth != w || sBitmapOptionsCache.outHeight != h) {
                             Bitmap tmp = Bitmap.createScaledBitmap(b, w, h, true);
                             b.recycle();
                             b = tmp;
                         }
                     }
                     return b;
                 } catch (FileNotFoundException e) { return null;
                 } catch (Exception e) { return null;
                 } finally {
                     try {
                         if (fd != null)
                             fd.close();
                     } catch (IOException e) {
                     }
                 }
             }
             return null;
      }

}

참조:
http://www.androidpub.com/32022

특히 getBitmapImage 는 댓글의 '아름다운 밤'님의 소스와 100% 동일함을 알려드립니다.

2011년 1월 19일 수요일

[안드로이드] mp3 한글 파일 이름 깨짐 현상 해결

 그렇다. 이것은 나는 나의 문제, 나의 코딩실력의 문제, 내가 부족해서 생겼다고 생각하였다. 그러나, However, but, whenever 이것은 안드로이드 구글 의 문제, 나의 문제가 아니었다.

 이럴 수가. 구글이 잘못 만들어서 나는 캐 고생을 해 버렸다 ㅠ 그래서 나는 해법을 찾아 하이에나가 먹이를 찾아 킬리만자로를 헤매듣이 헤맨 끝에 해결책을 발견하였다.

 미디어를 스캔하기 전에 언어를 한글로 바꿔줘야 하는 것이었다. 언어가 영어인 상태로 미디어를 한 번 스캔 해 버리면 그 후 언어를 한글로 바꿔줘도 깨져버린 파일들은 복구할 도리가 없다. 그러므로 미디어 스캔하기 전에 꼭 한글로 먼저 언어를 바꾼 후에 스캔하도록 하자.

 이미 영어로 지정된 상태에서 스캔을 해 버렸다면 파일들을 다 하드디스크로 옮긴 후 (그리고 sdcard에서는 없애고) 다시 스캔 하고 -> 한글로 언어 변경 -> 다시 미디어 스캔을 하면 된다.

 그 외 인코딩 해 놓은 파일을 바꿔주는 프로그램도 있다고 한다. 그 이름 하여 tagbear

 이 파일을 검색해서 다운 받으면 알아서 곰플레이어 서버에 있는 태그 정보들을 새로 입혀준다고 한다. 그래서 모든 mp3 파일에 앨범 태그라던지 이름 이라던지 모두 새로 고쳐준다.

 출처

2011년 1월 18일 화요일

[안드로이드] 미디어 플레이어 앨범 자켓 확인 및 만들기

 앨범 자켓이 없는 mp3는 왠지 허전하다.

 그리고 지금 현재 개발하고 있는 프로그램에서 앨범 자켓을 띄어와서 보여줘야 하므로 굉장히 필요하다.

 현재 mp3 파일들 중 대다수가 앨범 자켓이 뜨지 않는다. 이것은 앨범 자켓이 없어서 그런 것인가, 아니면 프로그램이 잘못 된 것인가. 하는 회의를 하기를 여러 수십 밤(은 오바고)

 그래서 서핑을 다시 열심히 하였다. 내가 원하는 것은 어떻게 해야 안드로이드에서 앨범 자켓 이미지를 잘 가져올 수 있을까? 그렇다. 이를 위해 찾고 또 찾은 끝에 드디어 원하는( 완벽히 일치하지는 않지만) 내용을 찾을 수 있었다.

 그것은 바로 윈도우 탐색기에서 mp3가 앨범 자켓이 있는 지 없는 지 확인하고 없다면 앨범 자켓을 만들어주는 방법에 대한 블로그였다. 그렇다. 이를 통해 나는 나의 문제점을 더 확실히 알 수 있게 되었다.

 mp3 의 자켓 만드는 방법 및 자켓 확인 방법
:http://linkovertheworld.blogspot.com/2010/04/blog-post_28.html

2011년 1월 7일 금요일

[안드로이드] 심플한 음악재생 오픈 소스( android music player open source)

 간단한 음악 재생 플레이어 소스를 발견하였다.

아래 사이트에서 확인하기 바란다.

리스트에 음악 재생 목록 들이 뜨고( sd card의 바탕화면에 존재하는 음악들)

해당 하는 제목을 클릭하면 해당 노래가 나온다.

출처: http://www.helloandroid.com/tutorials/musicdroid-audio-player-part-i