2013-12-18 64 views
0

我正在從URL鏈接播放視頻文件。我的URL看起來像:無法播放來自Url鏈接的.mp4文件

// this not works 
https://vimeo.com/81995018 

我測試了下面的鏈接它的工作,有些什麼答​​案here

// it works fine 
String LINK = "http://www.boisestatefootball.com/sites/default/files/videos/original/01%20-%20coach%20pete%20bio_4.mp4"; 

,當我和我的鏈接運行得到日誌貓錯誤,看起來:

12-18 12:25:19.207: D/MediaPlayer(1578): Couldn't open file on client side, trying server side 
12-18 12:25:19.217: E/MediaPlayer(1578): error (1, -2147483648) 
12-18 12:25:19.277: E/MediaPlayer(1578): Error (1,-2147483648) 
12-18 12:25:19.277: D/VideoView(1578): Error: 1,-2147483648 

我的動態類,如下所示:

public class MainActivity extends Activity { 

Context context = this; 
VideoView videoView; 
private ProgressDialog progressDialog; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    // it works fine 
    // String LINK = 
    // "http://www.boisestatefootball.com/sites/default/files/videos/original/01%20-%20coach%20pete%20bio_4.mp4"; 

    // this not works :(
    String LINK = "https://vimeo.com/81995018"; 

    videoView = (VideoView) findViewById(R.id.videoView_test); 
    MediaController mc = new MediaController(this); 
    mc.setAnchorView(videoView); 
    mc.setMediaPlayer(videoView); 
    Uri video = Uri.parse(LINK); 
    videoView.setMediaController(mc); 
    videoView.setVideoURI(video); 
    videoView.requestFocus(); 
    videoView.start(); 

} 
} 

我也試圖讓編解碼器/格式/規範的給定的視頻鏈接,以檢查我的Android 2.3.4Sony XPeria-New是否運行它。但也不能得到這個。

需要某人的超級敲門聲。謝謝。

回答

1

Link顯示了Android手機和平板電腦支持的文件,並提供了編解碼器和文件擴展名信息。但是,Android應用程序可以使用由任何由Android供電的設備提供的媒體編解碼器或由第三方公司開發的其他媒體編解碼器。因此,如果您想在Android上播放視頻,請查找多格式視頻播放器或將視頻轉換爲Android兼容格式。

查看此Android支持的媒體格式http://developer.android.com/guide/appendix/media-formats.html

+0

我也試圖讓給出的視頻鏈接的編解碼器/格式/規格,以檢查是否我的Android 2.3.4 *索尼XPERIA - 新*運行與否。但也不能得到這個。 @Murali –

+0

@shihab_returns您需要將此視頻轉換爲Android支持文件,例如:SD - 標準清晰度:H.264視頻編解碼器,視頻比特率高達500 Kbps,分辨率480x360像素,每秒30幀,AAC-LC音頻編解碼器,音頻比特率高達128 Kbps,立體聲音頻與.m4v,.mp4和.mov視頻容器 –

+0

請參閱此鏈接http://www.heywatchencoding.com/android-video-encoder –

1

這是僅適用於運行VimeoVideo

使用此兩類。

package com.example.newsolution; 

    import android.app.Activity; 
    import android.os.Bundle; 
    import android.view.KeyEvent; 

    public class Test extends Activity { 

     HTML5WebView mWebView; 

     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      mWebView = new HTML5WebView(this); 

      if (savedInstanceState != null) { 
       mWebView.restoreState(savedInstanceState); 
      } else {  
    //   mWebView.loadUrl("http://player.vimeo.com/video/27244727"); 
       mWebView.loadUrl("http://player.vimeo.com/video/81995018"); 
      } 

      setContentView(mWebView.getLayout()); 
     } 

     @Override 
     public void onSaveInstanceState(Bundle outState) { 
      super.onSaveInstanceState(outState); 
      mWebView.saveState(outState); 
     } 

     @Override 
     public void onStop() { 
      super.onStop(); 
      mWebView.stopLoading(); 
     } 

     @Override 
     public boolean onKeyDown(int keyCode, KeyEvent event) { 

      if (keyCode == KeyEvent.KEYCODE_BACK) { 
       if (mWebView.inCustomView()) { 
        mWebView.hideCustomView(); 
       // mWebView.goBack(); 
        //mWebView.goBack(); 
        return true; 
       } 

      } 
      return super.onKeyDown(keyCode, event); 
     } 
    } 
    package com.example.newsolution; 
import android.app.Activity; 
import android.content.Context; 
import android.graphics.Bitmap; 
import android.util.AttributeSet; 
import android.view.KeyEvent; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.view.Window; 
import android.webkit.GeolocationPermissions; 
import android.webkit.WebChromeClient; 
import android.webkit.WebSettings; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 
import android.widget.FrameLayout; 

public class HTML5WebView extends WebView { 

    private Context        mContext; 
    private MyWebChromeClient     mWebChromeClient; 
    private View        mCustomView; 
    private FrameLayout       mCustomViewContainer; 
    private WebChromeClient.CustomViewCallback mCustomViewCallback; 

    private FrameLayout       mContentView; 
    private FrameLayout       mBrowserFrameLayout; 
    private FrameLayout       mLayout; 

    static final String LOGTAG = "HTML5WebView"; 

    private void init(Context context) { 
     mContext = context;  
     Activity a = (Activity) mContext; 

     mLayout = new FrameLayout(context); 

     mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(a).inflate(R.layout.custom_screen, null); 
     mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(R.id.main_content); 
     mCustomViewContainer = (FrameLayout) mBrowserFrameLayout.findViewById(R.id.fullscreen_custom_content); 

     mLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS); 

     // Configure the webview 
     WebSettings s = getSettings(); 
     s.setBuiltInZoomControls(true); 
     s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); 
     s.setUseWideViewPort(true); 
     s.setLoadWithOverviewMode(true); 
     // s.setSavePassword(true); 
     s.setSaveFormData(true); 
     s.setJavaScriptEnabled(true); 
     mWebChromeClient = new MyWebChromeClient(); 
     setWebChromeClient(mWebChromeClient); 

     setWebViewClient(new WebViewClient()); 

setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); 

     // enable navigator.geolocation 
     // s.setGeolocationEnabled(true); 
     // s.setGeolocationDatabasePath("/data/data/org.itri.html5webview/databases/"); 

     // enable Web Storage: localStorage, sessionStorage 
     s.setDomStorageEnabled(true); 

     mContentView.addView(this); 
    } 

    public HTML5WebView(Context context) { 
     super(context); 
     init(context); 
    } 

    public HTML5WebView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     init(context); 
    } 

    public HTML5WebView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
     init(context); 
    } 

    public FrameLayout getLayout() { 
     return mLayout; 
    } 

    public boolean inCustomView() { 
     return (mCustomView != null); 
    } 

    public void hideCustomView() { 
     mWebChromeClient.onHideCustomView(); 
    } 

    @Override 
    public boolean onKeyDown(int keyCode, KeyEvent event) { 
     if (keyCode == KeyEvent.KEYCODE_BACK) { 
      if ((mCustomView == null) && canGoBack()){ 
       goBack(); 
       return true; 
      } 
     } 
     return super.onKeyDown(keyCode, event); 
    } 

    private class MyWebChromeClient extends WebChromeClient { 
     private Bitmap  mDefaultVideoPoster; 
     private View  mVideoProgressView; 

     @Override 
     public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) 
     { 
      //Log.i(LOGTAG, "here in on ShowCustomView"); 
      HTML5WebView.this.setVisibility(View.GONE); 

      // if a view already exists then immediately terminate the new one 
      if (mCustomView != null) { 
       callback.onCustomViewHidden(); 
       return; 
      } 

      mCustomViewContainer.addView(view); 
      mCustomView = view; 
      mCustomViewCallback = callback; 
      mCustomViewContainer.setVisibility(View.VISIBLE); 
     } 

     @Override 
     public void onHideCustomView() { 
      System.out.println("customview hideeeeeeeeeeeeeeeeeeeeeeeeeee"); 
      if (mCustomView == null) 
       return;   

      // Hide the custom view. 
      mCustomView.setVisibility(View.GONE); 

      // Remove the custom view from its container. 
      mCustomViewContainer.removeView(mCustomView); 
      mCustomView = null; 
      mCustomViewContainer.setVisibility(View.GONE); 
      mCustomViewCallback.onCustomViewHidden(); 

      HTML5WebView.this.setVisibility(View.VISIBLE); 
      HTML5WebView.this.goBack(); 
      //Log.i(LOGTAG, "set it to webVew"); 
     } 


     @Override 
     public View getVideoLoadingProgressView() { 
      //Log.i(LOGTAG, "here in on getVideoLoadingPregressView"); 

      if (mVideoProgressView == null) { 
       LayoutInflater inflater = LayoutInflater.from(mContext); 
       mVideoProgressView = inflater.inflate(R.layout.video_loading_progress, null); 
      } 
      return mVideoProgressView; 
     } 

     @Override 
     public void onReceivedTitle(WebView view, String title) { 
      ((Activity) mContext).setTitle(title); 
     } 

     @Override 
     public void onProgressChanged(WebView view, int newProgress) { 
      ((Activity) mContext).getWindow().setFeatureInt(Window.FEATURE_PROGRESS, newProgress*100); 
     } 

     @Override 
     public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { 
      callback.invoke(origin, true, false); 
     } 
    } 


    static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = 
     new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 
} 

Details在這裏