I can play a video from the Internet by inserting the URL like below:
mPath = Uri.parse(\"http://commonsware.com/misc/test2.3gp\");
mVid.setVideoURI(mPath)
I had the same problem. This worked for me:
Uri video = Uri.parse("android.resource://com.pac.myapp/raw/master");
So as you see you have 3 parts of the uri: 1) "android.resource://" 2) "com.pac.myapp" 3) "/raw/master"
"master" is the name of your video
this works for me
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();
}
});
}
}
Change my name if this doesn't works. 'ed' is the video file name.
You just need to locate song in raw folder under resource folder. if it is link then
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);
}
}
Enjoy playing video in surface view