2014-02-26 3 views
0

그러나 문을 인쇄하지만 음악을 재생하지 않습니다. 아래 코드를 게시했습니다.안드로이드에서 들어오는 메시지를 탐지하고 안드로이드에서 음악을 재생하는 방법은 무엇입니까?

if(intent.getAction().toString().equalsIgnoreCase("android.provider.Telephony.SMS_RECEIVED")) //.equalsIgnoreCase("android.provider.Telephony.SMS_RECEIVED")) 

    { 
     notificationfunction(); 
     System.out.println("message receive inside power receiver"); 
    } 
} 

private void notificationfunction() 
{ 
    /* // TODO Auto-generated method stub 
         if (mMediaPlayer.isPlaying()) // Checking if already playing any song 
         { 
          mMediaPlayer.reset(); 
          //mMediaPlayer.stop(); 

         } 
    */ 
    switch (np) 
    { 
    case R.id.nradioButton1: 
     mMediaPlayer = MediaPlayer.create(context, R.raw.notification1); 
     mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
     mMediaPlayer.setLooping(true); 

     if (mMediaPlayer.isPlaying()) // Checking if already playing any song 
     { 
      mMediaPlayer.reset(); 
     } 
     mMediaPlayer.start(); 
     break; 

    case R.id.nradioButton2: 
     mMediaPlayer = MediaPlayer.create(context, R.raw.notification2); 
     mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
     mMediaPlayer.setLooping(true); 
     if (mMediaPlayer.isPlaying()) // Checking if already playing any song 
     { 
      mMediaPlayer.reset(); 
     } 
     mMediaPlayer.start(); 
     break; 

    case R.id.nradioButton3: 
     mMediaPlayer = MediaPlayer.create(context, R.raw.notification3); 
     mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
     mMediaPlayer.setLooping(true); 
     if (mMediaPlayer.isPlaying()) // Checking if already playing any song 
     { 
      mMediaPlayer.reset(); 
     } 
     mMediaPlayer.start(); 
     break; 

    case R.id.nradioButton4: 
     mMediaPlayer = MediaPlayer.create(context, R.raw.notification4); 
     mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
     mMediaPlayer.setLooping(true); 

     if (mMediaPlayer.isPlaying()) // Checking if already playing any song 
     { 
      mMediaPlayer.reset(); 
     } 
     mMediaPlayer.start(); 
     break; 

    case R.id.nradioButton5: 
     mMediaPlayer = MediaPlayer.create(context, R.raw.notification5); 
     mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
     mMediaPlayer.setLooping(true); 

     if (mMediaPlayer.isPlaying()) // Checking if already playing any song 
     { 
      mMediaPlayer.reset(); 
     } 
     mMediaPlayer.start(); 

     break; 
    } 
} 

내가 어디 잘못했는지 알 수 없습니다. 아무도 이것으로 나를 도울 수 있습니까?

+0

적절한 코드를 입력하십시오. 현재 완전히 이해하기 어렵고 명확하지 않습니다 (예 : 첫 번째 기능은 무엇이고 'np'는 무엇입니까?)? 해 보셨습니까 http://stackoverflow.com/questions/3289038/play-audio-file-from-the-assets-directory 또는 http://stackoverflow.com/questions/8106694/play-media-files-located-in -assets-folder? – sandrstar

답변

0
당신은 당신의 스위치에 대해 확인하는 변수, 당신은 선택 라디오 버튼의 볼에 손을하지 않을 경우

 notificationfunction(View np){ 
    switch(np.getId()){ 
     //cases 
     } 
    } 

, 당신이 사용해야 넘겨하지 않은

경우와 다른 경우에 조건 보기의 스위치 대신 라디오 버튼의 상태 ids :

if(RadioButton1.ischecked()){ 
     //do something 
    }else if (RadioButton2.isChecked(){ 
     //do something else 
    }//etc. 
+0

답변을 선택하지 않으셔서 감사합니다! –

관련 문제