尝试从原始文件夹(VideoView)播放video

我可以通过插入如下的URL来从互联网上播放video:

mPath = Uri.parse("http://commonsware.com/misc/test2.3gp"); mVid.setVideoURI(mPath); mVid.requestFocus(); mVid.start(); 

但现在我有一个video在我的原始文件夹,所以path是res / raw / testing.3gp。 下面的代码不起作用,我也试过其他一些方法也无济于事。

 mPath = Uri.parse("../../res/raw/testing.3gp"); 

有什么build议么?

Solutions Collecting From Web of "尝试从原始文件夹(VideoView)播放video"

我有同样的问题。 这对我工作:

 Uri video = Uri.parse("android.resource://com.pac.myapp/raw/master"); 

所以你看到你有3个部分的uri:1)“android.resource://”2)“com.pac.myapp”3)“/ raw / master”

“主”是您的video的名称

这对我有用

  String videoName = nameWithoutFileExtention; int id = getResources().getIdentifier(videoName, "raw", getActivity().getPackageName()); final String path = "android.resource://" + getActivity().getPackageName() + "/" + id; vvBgVideo.setVideoURI(Uri.parse(path)); 
 public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn=(Button)this.findViewById(R.id.playvideo); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { VideoView vid=(VideoView)findViewById(R.id.video); vid.setMediaController(new MediaController(MainActivity.this)); Uri video = Uri.parse("android.resource://com.example.tenzinthinley.video/raw/ed"); vid.setVideoURI(video); vid.requestFocus(); vid.start(); } }); } } 

改变我的名字,如果这不起作用。 'ed'是video文件的名称。

您只需要在资源文件夹下的原始文件夹中find歌曲。 如果是链接的话

  private String urlVideo ="http://www.pocketjourney.com/downloads/pj/video/famous.3gp"; //Make uri from song located in raw folder Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.shakebooty); player.setUpVideoFrom(uri.toString()); public void setUpVideoFrom(String source) throws IllegalArgumentException, IllegalStateException, IOException { mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); //Only to check if you want to play song from url if (source.contains("http")) { mPlayer.setDataSource(source); } //If want to play song from uri you created from song in raw folder else { mPlayer.setDataSource(ctx, source); } } 

享受在表面视图播放video