播放视频从原始文件夹 [英] Play Video From Raw Folder
问题描述
晚报,
我刚开始与Android编程,并提出了一些方案和一切,所以我还是那种一个新手,但我试着去了解这一切。
I've just started programming with android and made a few programs and everything so I'm still kind of a novice but im trying to understand it all.
因此,这里是我的问题,我想播放视频的事情是,我得到了它,当我流时,从一个URL以VideoView在互联网上或当我把在我的SD卡的工作。
So here's my problem, I'm trying to play a video, the thing is, I got it working when I Stream it from an URL with VideoView over the internet or when i place in on my sdcard.
我想现在要做的就是发挥我已经在我的RES /原始文件夹中的视频,但它只能播放音频,我不明白为什么,它不给任何错误在我的logcat尽可能我所看到的,也不可能真正找到与谷歌的一个解决方案,因为大部分的答案是关于VideoView,只是把视频上你的SD卡。
What I want to do now is play a video I've got in my res/raw folder, but it only plays audio and I don't understand why, it doesn't give any error in my logcat as far as I can see, also couldn't really find a solution with google since most of the answers are about VideoView and just put the video on your SDCard.
现在有人告诉我,我不得不使用setDisplay(SurfaceHolder),我以前也试过,但我仍然只获得了音讯。
Now someone told me I had to use setDisplay (SurfaceHolder) and I've also tried that but I still only get the audio.
我希望有人能帮助我找到一个解决这个问题。
I hope somebody can help me to find a solution to this problem.
VideoDemo.java
VideoDemo.java
package nl.melvin.videodemo;
import android.app.Activity;
import android.os.Bundle;
import android.media.MediaPlayer;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class videodemo extends Activity {
public SurfaceHolder holder;
public SurfaceView surfaceView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MediaPlayer mp = MediaPlayer.create(this, R.raw.mac);
mp.setDisplay(holder);
mp.start();
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<SurfaceView
android:id="@+id/surfaceview"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</SurfaceView>>
</LinearLayout>
我也试过Uri.parse,但它说,它无法播放视频(.MP4格式)。
I've also tried Uri.parse but it says it can't play the video (.mp4 format).
推荐答案
我有同样的问题,仍然无法加载视频(只有声音)。 但是我没有这样的:
I had the same problem and still couldn't load the video (only the sound). However I did it like this:
getWindow().setFormat(PixelFormat.TRANSLUCENT);
videoView = new VideoView(this);
videoView.setMediaController(new MediaController(this));
videoView.setVideoURI(Uri.parse("android.resource://pt.beware.smdemo/" + R.raw.video));
videoView.requestFocus();
videoView.start();
setContentView(videoView);
这篇关于播放视频从原始文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!