Ben android video görünümünde stream video form url istiyorum. Benim iş parçacığı üzerinde bu işlemek için herhangi bir şekilde orada alt sının i video akışı için uithread kullanıyorum görebilirsiniz benim ihtiyaç .Benim kod İşteAndroid Video Başka bir Thread & Sayı android ile görüntü 2.1
public class VideoViewDemo extends Activity {
private static final String TAG = "VideoViewDemo";
private String current;
/**
* TODO: Set the path variable to a streaming video URL or a local media
* file path.
*/
private String path = "http://www.boisestatefootball.com/sites/default/files/videos/original/01%20-%20coach%20pete%20bio_4.mp4";
private VideoView mVideoView;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.videoview);
mVideoView = (VideoView) findViewById(R.id.surface_view);
runOnUiThread(new Runnable() {
public void run() {
playVideo();
}
});
}
private void playVideo() {
try {
// final String path = path;
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.setMediaController(new MediaController(this));
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;
}
}
}
olduğunu ulaşmak için bu örnek API kodu ve yapılan küçük bir değişiklik kullanan denedim ne
new Thered(new Runnable() {
public void run() {
playVideo();
}
}).start();
olduğunu Ama Android 2.2 İlk kod çalışır planda çalışırken aynı zamanda
ve başarısız ve error(-38,0)
gösterir i n Android 2.1 bu hata nedir? This File'u kontrol ettim, ancak bu hangi hatayı bulamadı?
Herkes bana rehberlik edebilir mi ??
Düğme 'Video Oynat' deyin ve tıklama işlevinde Runnable Thread kodunuzu yerleştirin. OnCreate() işlevindeki kendi iş parçacığınızın olması, etkinlik oluşturmanın her zaman iyi olması gerektiğinden uygun şekilde ele alınmadığında dağınık olabilir. Bu arada Android emülatöründe veya Telefonda bunu denediniz mi? –
@RahulSundar Telefonda denedim. Düğmeyi kullanmak istemedim. Etkinliğe girdiğimde videoyu doğrudan oynatmak istiyorum. bu yüzden hiç bir buton kullanmadım – edwin
Tamam. Sadece her şeyin iş parçacığıyla iyi çalışıp çalışmadığını kontrol etmek için bir düğmeden başlatın. Sonra aynı OnCreate() işlevinde kullanın. Etkinlik oluşturma işleminin tamamlanmasından sonra video oluşturma işleminin başladığından emin olmak için, yeterli Gecikme süresini (5 saniye) verin ve her şeyin düzgün çalışıp çalışmadığını kontrol edin. –