2017-07-09 34 views
0

我正在製作手指手語應用程序。 我已經設法從用戶​​輸入中獲取字符串的子字符串。 現在,每個字母都有來自我的sqlite的相應視頻文件,我希望它在每個字母后一次播放一個視頻視圖。如何從sqlite非同時(排隊)播放多個視頻到videoView通過循環?

表:

| letter | videofilename |

| a | lettera |

| b | letterb |

| c | letterc |等等。

public void fingerspell(View v) { 
    CharSequence charSequence = etsearch.getText(); 
    String s = charSequence.toString(); 
    int startingletter = 0; 
    int endingletter = 1; 
    String desiredString; 
    int wordlength = etsearch.length(); 
     do{ 

     desiredString = s.substring(startingletter, endingletter); 
     Cursor c = db.rawQuery("SELECT * FROM tblletters WHERE letter like '" + desiredString + "'", null); 
      while (c.moveToNext()) { 
       Toast.makeText(getApplicationContext(), desiredString, Toast.LENGTH_LONG).show(); 
       String video = c.getString(1); 
       int videoResource = getResources(). 
         getIdentifier(video, "raw", getPackageName()); 
       String path = "android.resource://" + getPackageName() + "/" + videoResource; 
       videoview.setVideoURI(Uri.parse(path)); 
       videoview.start(); 
       videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 
        public void onCompletion(MediaPlayer mp) { 
         //can't put startingletter++ here 
        } 
       }); 


       startingletter++; 
       endingletter++; 
      } 
     startingletter++; 
      endingletter++; 
    }while(startingletter<wordlength); 
} 

只有敬酒作品,它播放第一個視頻,但不播放下一個。

回答

0

我找到了一種方法,我不確定這是否是正確的編碼,但現在它的工作。基於什麼理解,我正在循環videoview.setOnCompletionListener,即使它已經是一個循環,並且我還將增量變量聲明爲全局變量,因此可以從內部類訪問。我是編程新手。

CharSequence charSequence = etsearch.getText(); 
     String s = charSequence.toString(); 
     int startingletter = 0; 
     String desiredString; 
     int wordlength = etsearch.length(); 
     final ArrayList<String> list = new ArrayList<String>(); 

     while (startingletter < wordlength) { 
      desiredString = s.substring(startingletter, startingletter + 1); 
      list.add(desiredString); 
      startingletter++; 
     } 


     // Toast.makeText(getApplicationContext(), list.get(3), Toast.LENGTH_LONG).show(); 


     listsize = list.size(); 
     pogi = list.get(0); 

     // Toast.makeText(getApplicationContext(), pogi, Toast.LENGTH_LONG).show(); 
     Cursor c = db.rawQuery("SELECT * FROM tblletters WHERE letter like '" + pogi + "'", null); 
     while (c.moveToNext()) { 
      String video = c.getString(1); 
      int videoResource = getResources(). 
        getIdentifier(video, "raw", getPackageName()); 
      String path = "android.resource://" + getPackageName() + "/" + videoResource; 
      videoview.setVideoURI(Uri.parse(path)); 
      videoview.start(); 
     } 


     videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 
      public void onCompletion(MediaPlayer mp) { 
       halimaw++; 
       if (halimaw < listsize) { 
        pogi = list.get(halimaw); 

        Cursor c = db.rawQuery("SELECT * FROM tblletters WHERE letter like '" + pogi + "'", null); 
        c.moveToNext(); 
        String video = c.getString(1); 
        int videoResource = getResources(). 
          getIdentifier(video, "raw", getPackageName()); 
        String path = "android.resource://" + getPackageName() + "/" + videoResource; 
        videoview.setVideoURI(Uri.parse(path)); 
        videoview.start(); 
       } else { 
        halimaw = 0; 
        pogi = ""; 
       } 
       //Toast.makeText(getApplicationContext(), "tapos na", Toast.LENGTH_LONG).show(); 
      } 
     });