誰かが Android Mediaplayer でローカルのオーディオ/ビデオ ファイルを再生する方法を理解するのを手伝ってくれるかどうか疑問に思っています...URL アドレスを保持する変数を使用して URL からオーディオ/ビデオをストリーミングできますが、ローカル ファイルでそれを行うにはどうすればよいですか? localFile 変数を使用してローカル ファイルを呼び出して再生する方法は? みんな、ありがとう!
package com.ryanleckey2;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class Audio_Video_Stream extends BT_activity_base{
private String localFile = "";
private String localFileName = "";
private String dataURL = "";
private String currentURL = "";
public String thisActivityName = "Screen_Video";
//movie controller
String videoUrl;
VideoView videoView;
MediaController mediaController;
public int isLoading;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen_video);
//fill JSON properties...
dataURL = BT_strings.getJsonPropertyValue(this.screenData.getJsonObject(), "dataURL", "");
currentURL = dataURL;
localFileName = BT_strings.getJsonPropertyValue(this.screenData.getJsonObject(), "localFileName", "");
//setup the saveAsFileName
if(localFileName.length() > 1){
//use the file name in the JSON data...
localFile = localFileName;
//Log.i("ZZ", thisActivityName + ":videoUrl : " + videoUrl);
videoView = (VideoView) findViewById(R.id.videoView);
mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
isLoading = 0;
}
}
///////////////////////////////////////////////////
//activity life-cycle overrides
//onStart
@Override
protected void onStart(){
super.onStart();
//Log.i("ZZ", thisActivityName + ":onStart");
}
//onResume
@Override
public void onResume() {
super.onResume();
if(isLoading == 1){
if(videoView != null){
videoView = null;
}
}
startMovie();
//Log.i("ZZ", thisActivityName + ":onResume");
}
//onPause
@Override
public void onPause() {
//Log.i("ZZ", thisActivityName + ":onPause");
super.onPause();
if(videoView != null){
videoView = null;
}
}
//onStop
@Override
protected void onStop(){
super.onStop();
//Log.i("ZZ", thisActivityName + ":onStop");
}
//onDestroy
@Override
public void onDestroy() {
//Log.i("ZZ", thisActivityName + ":onDestroy");
super.onDestroy();
}
//activity life-cycle overrides
///////////////////////////////////////////////////
//starts movie
public void startMovie(){
//show progress for a few seconds..
showProgress("Starting media stream...", "Please be patient. If you're on 3G this could take a bit.\nWi-Fi is much better for streaming.");
isLoading = 1;
try{
//set audio/video link (mp4,mp3 format )
mediaController = new MediaController(this);
Uri uri = Uri.parse(currentURL);
//Uri uri=Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.);
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.setOnPreparedListener(mOnPreparedListener);
videoView.start();
}catch(Exception je){
hideProgress();
showAlert("Invalid URL","The URL to the media could not be determined. This screen will close.");
finish();
}
}
//onPrepared...
private MediaPlayer.OnPreparedListener mOnPreparedListener = new MediaPlayer.OnPreparedListener(){
public void onPrepared(MediaPlayer mp){
//Log.i("ZZ", thisActivityName + ":OnPreparedListener");
isLoading = 0;
// mp.setLooping(true);
hideProgress();
}
};
}