2016-08-01 6 views
0

再生することができれば:チェックし、インターネットからのvideoviewのためのリソース教材は、私がvideoviewを使用してインターネット上でプレイ映像からしようとしている

String path1="http://someserverhere.com 
Uri uri=Uri.parse(path1); 
VideoView video=(VideoView)findViewById(R.id.VideoView01); 
video.setVideoURI(uri); 
video.start(); 

は、どのように私はビデオリソース教材は(例外を処理するために)再生することができ知ることができ、これを私はずっと試みました:

try { 
     MediaPlayer mp = new MediaPlayer(); 
     mp.setDataSource(this, uri); 
     mp.release(); 
    } 
    catch (Exceptione) { 

    } 

しかし、このコードは - メディアプレイヤーが私の画面をハングアップします。 これについて何かお答えくださいか? Tksたくさん。ファイルには、次のコードを使用してビデオの幅と高さをチェックして、それを確認することができますヘッダー要求

import java.net.*; 
import java.io.*; 

public static boolean isFileExist(String URLName){ 
    try { 
     HttpURLConnection.setFollowRedirects(false); 
     //you may also need HttpURLConnection.setInstanceFollowRedirects(false) 
     HttpURLConnection con = 
       (HttpURLConnection) new URL(URLName).openConnection(); 
     con.setRequestMethod("HEAD"); 
     return (con.getResponseCode() == HttpURLConnection.HTTP_OK); 
    } 
    catch (Exception e) { 
     e.printStackTrace(); 
     return false; 
    } 
} 
+0

あなたは私の答えを見たことがありますか? –

答えて

0

たぶん、あなたは確認することができます。

MediaMetadataRetriever mRetriever = new MediaMetadataRetriever(); 
mRetriever.setDataSource(context, uri); 
Bitmap frame = mRetriever.getFrameAtTime(); 

int width = frame.getWidth(); 
int height = frame.getHeight(); 
+0

ファイルが動画ファイルかどうかを確認していますか? – user3693265

+0

私が知る限り、あなたはできません。 BtwあなたはURLからのファイルの拡張子からチェックすることができますが、正確ではありません。または、MediaPlayerでonErrorListenerを設定できるため、ビデオの読み込みに失敗した場合はエラーをキャッチします – HendraWD

0

に存在している場合

0

ビデオをフルコードで再生する。

注:マニフェストにインターネットアクセス許可を追加します。

<uses-permission android:name="android.permission.INTERNET" />

public class MainActivity extends Activity { 

    ProgressDialog pDialog; 
    VideoView videoview; 

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


     String VideoURL = "http://clips.vorwaerts-gmbh.de/VfE_html5.mp4"; 
     videoview = (VideoView) findViewById(R.id.videoView); 

     pDialog = new ProgressDialog(this); 
     pDialog.setTitle("Android Video Streaming Demo"); 
     pDialog.setMessage("Buffering..."); 
     pDialog.setIndeterminate(false); 
     pDialog.setCancelable(false); 
     pDialog.show(); 

     try { 
      // Start the MediaController 
      MediaController mediacontroller = new MediaController(this); 
      mediacontroller.setAnchorView(videoview); 
      // Get the URL from String VideoURL 
      Uri video = Uri.parse(VideoURL); 
      videoview.setMediaController(mediacontroller); 
      videoview.setVideoURI(video); 

     } catch (Exception e) { 
      Log.e("Error", e.getMessage()); 
      e.printStackTrace(); 
     } 

     videoview.requestFocus(); 
     videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 
      // Close the progress bar and play the video 
      public void onPrepared(MediaPlayer mp) { 
       pDialog.dismiss(); 
       videoview.start(); 
      } 
     }); 
    } 
} 
関連する問題