2016-09-17 3 views
-3

を使用して、異なるRaw素材をMediaPlayerに割り当てます。私のスイッチステートメントでMediaPlayerに異なるRawアイテムを割り当てることができますか?ここスイッチステートメント

は私のMediaPlayerが

final MediaPlayer mp2 = MediaPlayer.create(context, R.raw.doa_tawaf_round_1); 
    holder.imageButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      if (mp2.isPlaying()) { 
       mp2.pause(); 
       holder.imageButton.setImageResource(R.drawable.tawaf_play_btn); 
      } else { 
       mp2.start(); 
       holder.imageButton.setImageResource(R.drawable.tawaf_pause_btn); 
       holder.secImageButton.setVisibility(View.VISIBLE); 
      } 
     } 
    }); 

であり、これは私のSwitchステートメントである

switch (position) 
      { 
       case 0: 
        if(point == 0) { 
         holder.rukunName.setText(R.string.rukun_hajar_aswad); 
         holder.duaText.setText(ArabicUtilities.reshapeSentence(context.getResources().getString(R.string.doa_permulaan_tawaf))); 
         holder.secDuaText.setText(ArabicUtilities.reshapeSentence(context.getResources().getString(R.string.doa_tawaf_pusingan_pertama))); 
         mp2.setRaw(R.raw.myRawFile); //Any idea what to use in here ? 
        } break; 
       case 1: if(point == 0){ 
         holder.rukunName.setText(R.string.rukun_hajar_aswad); 
         holder.duaText.setVisibility(View.GONE); 
         holder.secDuaText.setText(ArabicUtilities.reshapeSentence(context.getResources().getString(R.string.doa_tawaf_pusingan_kedua))); 
         mp2.setRaw(R.raw.mySecondRawfile); // And also here 

        }break; 
    } 

私の場合0のために非常に長い「場合」、私はそれをカットし、ここに貼り付けるように尋ねるいけないalraedy私の "ケース"または "if"ステートメント:)。 RAW入力メソッドの助けがあれば良いでしょう。

答えて

0

これは役に立ちます。あなたは2番目のパラメータとしてRAWファイルとメディアプレーヤーを作成することができますMediaPlayerで生のメディアファイルを再生するために

mp = MediaPlayer.create(context, R.raw.myRawFile); 

あなたのswitch文は以下のようになります

switch (position) 
      { 
       case 0: 
        if(point == 0) { 
         holder.rukunName.setText(R.string.rukun_hajar_aswad); 
         holder.duaText.setText(ArabicUtilities.reshapeSentence(context.getResources().getString(R.string.doa_permulaan_tawaf))); 
         holder.secDuaText.setText(ArabicUtilities.reshapeSentence(context.getResources().getString(R.string.doa_tawaf_pusingan_pertama))); 
         mp = MediaPlayer.create(context, R.raw.myRawFile); //You got the idea now 
        } break; 
       case 1: if(point == 0){ 
         holder.rukunName.setText(R.string.rukun_hajar_aswad); 
         holder.duaText.setVisibility(View.GONE); 
         holder.secDuaText.setText(ArabicUtilities.reshapeSentence(context.getResources().getString(R.string.doa_tawaf_pusingan_kedua))); 
         mp = MediaPlayer.create(context, R.raw.mySecondRawFile); // And now 

        }break; 
    } 
関連する問題