2013-03-11 82 views
-2

我想開發與呈現相同的視頻的質量不同勢就像在YouTube上改變質量功能的視頻播放器一個Android應用程序。如何發展不同勢視頻品質的Android視頻流應用中的Youtube(更改質量)

Proir給我很想知道源是否應包含提供給動態呈現它們的所有表裏如一選項的視頻。

任何幫助真誠讚賞。

我的代碼從URL dtream視頻。

公共類VideoViewDemo延伸活動{ 私有靜態最後字符串標記= 「VideoViewDemo」;

private VideoView mVideoView; 
private EditText mPath; 
private ImageButton mPlay; 
private ImageButton mPause; 
private ImageButton mReset; 
private ImageButton mStop; 
private String current; 

@Override 
public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    setContentView(R.layout.main); 
    mVideoView = (VideoView) findViewById(R.id.surface_view); 

    mPath = (EditText) findViewById(R.id.path); 
    mPath.setText("http://daily3gp.com/vids/747.3gp"); 

    mPlay = (ImageButton) findViewById(R.id.play); 
    mPause = (ImageButton) findViewById(R.id.pause); 
    mReset = (ImageButton) findViewById(R.id.reset); 
    mStop = (ImageButton) findViewById(R.id.stop); 

    mPlay.setOnClickListener(new OnClickListener() { 
     public void onClick(View view) { 
      playVideo(); 
     } 
    }); 
    mPause.setOnClickListener(new OnClickListener() { 
     public void onClick(View view) { 
      if (mVideoView != null) { 
       mVideoView.pause(); 
      } 
     } 
    }); 
    mReset.setOnClickListener(new OnClickListener() { 
     public void onClick(View view) { 
      if (mVideoView != null) { 
       mVideoView.seekTo(0); 
      } 
     } 
    }); 
    mStop.setOnClickListener(new OnClickListener() { 
     public void onClick(View view) { 
      if (mVideoView != null) { 
       current = null; 
       mVideoView.stopPlayback(); 
      } 
     } 
    }); 
    runOnUiThread(new Runnable(){ 
     public void run() { 
      playVideo(); 

     } 

    }); 
} 

private void playVideo() { 
    try { 
     final String path = mPath.getText().toString(); 
     Log.v(TAG, "path: " + path); 
     if (path == null || path.length() == 0) { 
      Toast.makeText(VideoViewDemo.this, "File URL/path is empty", 
        Toast.LENGTH_LONG).show(); 

     } else { 
      // If the path has not changed, just start the media player 
      if (path.equals(current) && mVideoView != null) { 
       mVideoView.start(); 
       mVideoView.requestFocus(); 
       return; 
      } 
      current = path; 
      mVideoView.setVideoPath(getDataSource(path)); 
      mVideoView.start(); 
      mVideoView.requestFocus(); 

     } 
    } catch (Exception e) { 
     Log.e(TAG, "error: " + e.getMessage(), e); 
     if (mVideoView != null) { 
      mVideoView.stopPlayback(); 
     } 
    } 
} 

private String getDataSource(String path) throws IOException { 
    if (!URLUtil.isNetworkUrl(path)) { 
     return path; 
    } else { 
     URL url = new URL(path); 
     URLConnection cn = url.openConnection(); 
     cn.connect(); 
     InputStream stream = cn.getInputStream(); 
     if (stream == null) 
      throw new RuntimeException("stream is null"); 
     File temp = File.createTempFile("mediaplayertmp", "dat"); 
     temp.deleteOnExit(); 
     String tempPath = temp.getAbsolutePath(); 
     FileOutputStream out = new FileOutputStream(temp); 
     byte buf[] = new byte[128]; 
     do { 
      int numread = stream.read(buf); 
      if (numread <= 0) 
       break; 
      out.write(buf, 0, numread); 
     } while (true); 
     try { 
      stream.close(); 
     } catch (IOException ex) { 
      Log.e(TAG, "error: " + ex.getMessage(), ex); 
     } 
     return tempPath; 
    } 
} 

}

感謝, 阿賈伊

+0

你累嗎? – DjHacktorReborn 2013-03-11 09:44:03

+0

我已經嘗試過使用VideoView類的基本視頻流應用程序,但不知道更改視頻的質量。順便說一下,我對這項技術很陌生。謝謝。 – user2156192 2013-03-11 09:58:21

+0

在這裏發表你有什麼嘗試。 – 2013-03-11 10:03:14

回答

0

嗨得到它通過對setOnClickListener事件下面的方法解決得videow鑑於目前現在的位置,改變了視頻源到高清和使用SeekTo方法與目前的然後啓動高清視頻,以便高清視頻可以從當前的SD視頻位置開始播放。

相關問題