2014-01-23 5 views
1

는 말한다 :로드 SoundPool은 <a href="http://developer.android.com/google/play/expansion-files.html#ZipLib" rel="nofollow">documentation</a>에서

미디어 파일을 저장하는 확장 파일을 사용하는 경우는, ZIP 파일 는 여전히 안드로이드 미디어 재생 호출을 사용할 수 있도록 그 오프셋 및 길이 컨트롤 (예 : MediaPlayer.setDataSource() 및 SoundPool.load()) 을 제공하십시오.

나는 10 개 작은에는 OGG 파일을 가지고 있고 나는이 오디오 파일을로드 할 수 SoundPool.load (FileDescriptor에의 FD, 긴 오프셋, 긴 길이, INT 우선 순위)를 사용하고 싶습니다. 나는 몇 가지 코드를 작성했습니다,하지만 난 그것을 실행할 때 오류 메시지가 얻을 :

을 "샘플로드 할 수 없습니다 : (null)와"

을 분명히 오디오가 재생되지 않습니다. 다음은 내가 시도한 것입니다.

public class MainActivity extends Activity { 

    SoundPool sounds; 
    boolean loaded = false; 
    int streamID; 
    int theId; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     System.gc(); 
     setContentView(R.layout.activity_main); 
     sounds = new SoundPool(10, AudioManager.STREAM_MUSIC,0); 
     sounds.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { 
      @Override 
      public void onLoadComplete(SoundPool sp, int sid, int status) { 
       loaded = true; 
     }}); 
     loadSounds(); 
     playSound(theID); 
    } 

    private void loadSounds() { 
     AssetFileDescriptor descriptor = null; 
     try { 
      descriptor = getFileDescriptor(this, "audio_files/end_credits.ogg"); 
     } catch (Exception e) { 
     } finally { 
      if (descriptor != null) 
       try{descriptor.close();} catch (IOException e) {} 
     } 
    theId = sounds.load(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength(), 1); 
} 
    public static AssetFileDescriptor getFileDescriptor(Context ctx, String path) { 
     AssetFileDescriptor descriptor = null; 
     try { 
      ZipResourceFile zip = APKExpansionSupport.getAPKExpansionZipFile(ctx, 4, -1); 
      descriptor = zip.getAssetFileDescriptor(path); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     return descriptor; 
    } 
    private void playSound(int soundID){ 
     if(loaded){ 
      streamID = sounds.play(soundID, 1, 1, 1, 0, 1);} 
    } 
} 

답변

0

좋아, 오디오가 충분히 빠르지 않는 것 같습니다. 나는 playSound (theID)를 넣었다. 바로 다음에 loadSounds(); 연주하기 전에 몇 초간로드해야합니다. 그러나 코드는 그 시점까지 작업 중입니다.

관련 문제