2013-02-16 2 views
1

.mp3 파일 및 문자열의 arraylist를 만들고 싶습니다. arraylist의 문자열이 임의의 mp3 파일보다 재생되면 재생됩니다. arraylist를 .mp3 파일과 Strings로 채워서 동시에 호출 할 수 있도록하거나 별도의 arrayLists를 만들겠습니까? 또는 .mp3 파일의 ArrayList를 사용하지 않을 수도 있습니다. 고맙습니다.Android, .mp3 파일의 arraylist 만들기?

ArrayList<String? words = new ArrayList<String> 
words.add("Hello World"); 

//On Button Click 
//Generates randomNumber Integer 
//randomNumber=1 
//SetText to "Hello World" and play .mp3 that says "Hello World" simultaneously and put thread to sleep for .mp3 length 

최소 하드 코딩의 양을 줄이는 가장 좋은 방법은 무엇입니까?

답변

0

원하는 것은 문자열을 MP3 파일 경로와 연관시키는 Map입니다. 다음과 같이

0

당신은

public class SongInfo 
{ 
    String songName; 
    String songPath; 


    public SongInfo(String songName,String songPath){ 
     this.songName = songName; 
     this.songPath = songPath; 

    } 
} 

ArrayList<SongInfo> customSongList = new ArrayList<SongInfo>(); 
0

public class Player { 

    public static void main(String[] args) { 
     Player player = new Player(); 
     //populate music in your arrayList 
     List<Song> album = player.populateMusicList(); 
     //play 
     for (int i = 0; i < 10; i++) { 
      player.play(album); 
     } 
    } 

    public void play(List<Song> album) { 
     System.out.println("playing --" + album.get(this.fetchMusicRandomly(album))); 
    } 

    private int fetchMusicRandomly(List<Song> album) { 
     return ThreadLocalRandom.current().nextInt(0, album.size()); 
    } 

    private List<Song> populateMusicList() { 
     List<Song> musicBucket = new ArrayList<Song>(); 
     musicBucket.add(new Song("musicName-1", "pathtomp3File")); 
     musicBucket.add(new Song("musicName-2", "pathtomp3File")); 
     musicBucket.add(new Song("musicName-3", "pathtomp3File")); 
     musicBucket.add(new Song("musicName-4", "pathtomp3File")); 
     musicBucket.add(new Song("musicName-5", "pathtomp3File")); 
     musicBucket.add(new Song("musicName-6", "pathtomp3File")); 
     musicBucket.add(new Song("musicName-7", "pathtomp3File")); 
     musicBucket.add(new Song("musicName-8", "pathtomp3File")); 
     musicBucket.add(new Song("musicName-9", "pathtomp3File")); 
     musicBucket.add(new Song("musicName-10", "pathtomp3File")); 
     return musicBucket; 
    } 

    class Song { 

     public Song(String name, String pathToMp3) { 
      this.name = name; 
      this.pathToMp3 = pathToMp3; 
     } 
     String name; 
     String pathToMp3; 

     public String getName() { 
      return name; 
     } 

     public String getPathToMp3() { 
      return pathToMp3; 
     } 

     @Override 
     public String toString() { 
      StringBuilder result = new StringBuilder(); 
      result.append(" {Name: " + name + " }"); 
      result.append(" {Path To Mp3file: " + pathToMp3); 
      result.append("}"); 
      return result.toString(); 
     } 
    } 
} 
무작위로 그것에서 자신의 노래 개체 및 픽업 노래를합니다 .. 객체의 사용자 정의의 ArrayList를 만들 수 있습니다