2017-11-05 14 views
0

재생할 수 없습니다하지만soundpool 내가 soundpool</p> <p>를 사용하여 경보를 만들기 위해 노력하고있어

11-05 (16) 아래에 몇 가지 문제가 있어요 : 42 : 36.094 20402-20432/com.example을 .lab714_pc.drug D/EGL_emulation : eglMakeCurrent : 0xa99850c0 : ver 3 1 (tinfo 0xa9983260) 11-05 16 : 44 : 02.883 20402-20402/com.example.lab714_pc.drug E/TEST : TEST 11-05 16 : 44 : 02.885 20402-21761/com.example.lab714_pc.drug E/WVMExtractor : libwvm.so를 열지 못했습니다. dlopen failed : 라이브러리 "libwvm.so"을 찾을 수 없습니다. 11-05 16 : 44 : 02.885 20402-20402/com .example.lab714_pc.drug W/SoundPool : 샘플 1은하지 11-05 16 READY : 44 : 02.888 20402-21762이/com.example.lab714_pc.drug 나는/OMXClient는 : MuxOMX의 ctor는

다음은

다음
public class PlayReceiver extends BroadcastReceiver { 

private SoundPool sp; 
private boolean spLoader = false; 
private int sourceid; 

@Override 
public void onReceive(Context context, Intent intent) { 

    Bundle bData = intent.getExtras(); 

    if (bData.get("msg").equals("play_voice")) { 

     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 

      AudioAttributes audioAttrib = new AudioAttributes.Builder() 
        .setUsage(AudioAttributes.USAGE_GAME) 
        .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) 
        .build(); 
      sp= new SoundPool.Builder().setAudioAttributes(audioAttrib).setMaxStreams(6).build(); 
      Log.e("TEST","TEST"); 
     } 
     else { 

      sp = new SoundPool(6, AudioManager.STREAM_MUSIC, 0); 
      Log.e("TEST","TEST"); 
     } 
     sp.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { 
      @Override 
      public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { 
       if (sampleId == R.raw.test) { 
        spLoader = true; 
       } 
      } 
     }); 




     sourceid = sp.load(context, R.raw.test, 1); 


     playSounds(1, context); 

    } 

} 

public void playSounds(int repeatTime, Context context) { 
    AudioManager am = (AudioManager) context.getApplicationContext() 
      .getSystemService(Context.AUDIO_SERVICE); 

    float audMaxVolumn = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); 

    float audCurrentVolumn = am.getStreamVolume(AudioManager.STREAM_MUSIC); 

    float volRatio = audCurrentVolumn/audMaxVolumn; 

    sp.play(sourceid, volRatio, volRatio, 1, repeatTime, 1); 
    } 
} 

는 주요 내 코드입니다 알람

Intent intent11 = new Intent(MainActivity.this, PlayReceiver.class); 
      intent11.putExtra("msg", "play_voice"); 
      intent11.addCategory(String.valueOf(SystemClock.elapsedRealtime())); 

      long elapsed = SystemClock.elapsedRealtime() + 60 * 1000; //60秒 

      PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 1, intent11, 
        PendingIntent.FLAG_UPDATE_CURRENT); 
      AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); 
      am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, elapsed , pi); 
+0

일을 내가 mp3 형식의 사운드 데이터? 대신 m4a를 시도하십시오. – muratgu

답변

0

나는 아래에 코드를 변경하며

public class PlayReceiver extends BroadcastReceiver { 

private SoundPool sp; 
private boolean spLoader = false; 



@Override 
public void onReceive(Context context, Intent intent) { 

    Bundle bData = intent.getExtras(); 



    if (bData.get("msg").equals("play_voice")) { 

     SoundPool sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); 

     /** soundId for Later handling of sound pool **/ 
     int soundId = sp.load(context, R.raw.test, 1); // in 2nd param u have to pass your desire ringtone 

     sp.play(soundId, 1, 1, 0, 0, 1); 

     MediaPlayer mPlayer = MediaPlayer.create(context, R.raw.test); // in 2nd param u have to pass your desire ringtone 
     //mPlayer.prepare(); 
     mPlayer.start(); 





    } 

}