I want to add a youtube video to my page. I downloaded the video and added it into the res-> raw folder. The video is marked minecraft_trailer.mp4. I am getting an error in the javascript page and I cant figure out what it is. Please help.
package com.treacheryofimages.www;
import android.app.Activity;
import android.os.Bundle;
import android.widget.VideoView;
public class OtherActivity7 extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.other7);
}
VideoView vv = (VideoView)this.findViewById(R.id.videoView1);
String fileName = "android.resource://" + getPackageName() + "/" +
R.raw.minecraft_trailer;
vv.setVideoURI(Uri.parse(minecraft_trailer));
vv.start();
}
}
The error is coming from the vv.setVideoURI(Uri.parse(minecraft_trailer)); line
I cant tell what it is. Its possibly whats inside the ().
Also, what is supposed to go inside those ()
You are passing the wrong variable minecraft_trailer when calling vv.setVideoURI();
it should be vv.setVideoURI(Uri.parse(fileName ));
check this out :
VideoView vd = (VideoView) findViewById(R.id.VideoView);
Uri uri = Uri.parse("android.resource://"+getPackageName() + "/"+R.raw.video);
mc = new MediaController(this);
vd.setMediaController(mc);
vd.setVideoURI(uri);
vd.start();
Related
This question already has answers here:
Unfortunately MyApp has stopped. How can I solve this?
(23 answers)
Closed 1 year ago.
Actually I want to incooperate multiple videos in a single xml file .But while adding I am getting error.
Actually I am confused why the error has occurred.So I have attached my java code below .The part which i wrote in bold Im getting error over there.I want to add mutiple videos in one page.So I was trying that.
public class bvideos extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bvideos);
VideoView videoView = findViewById(R.id.video_view1);
String videoPath = "android.resource://" + getPackageName() + "/" + R.raw.bvideo1;
VideoView **videoView** = findViewById(R.id.video_view1);
String **videoPath** = "android.resource://" + getPackageName() + "/" + R.raw.bvideo1;
Uri uri = Uri.parse(videoPath);
videoView.setVideoURI(uri);
MediaController mediaController = new MediaController(this);
videoView.setMediaController(mediaController);
mediaController.setAnchorView(videoView);
}
}
// make an array or Uri data type and add uri's in it
MediaController mc = new MediaController(this);
mc.setPrevNextListeners(new View.OnClickListener() {
#Override
public void onClick(View v) {
// get video from next index and set to video view
}
}, new View.OnClickListener() {
#Override
public void onClick(View v) {
// get video from previous index and set to video view
}
});
videoView.setMediaController(mc);
I have been modifying an example video player code; the example code played the video from the program resource directory. I copied the video to the phone's /storage/emulated/0/DCIM/ directory and add three lines:
String videoName1 = Environment.getExternalStorageDirectory().getPath()+"/DCIM/steprock";
Uri videoUri = Uri.parse(videoName1);
videoView.setVideoURI(videoUri);
to replace:
videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.steprock));
This change causes a file not found error. The video is in the Phone storage DCIM directory. I also tried adding the .mp4 to the video name.
In debug mode the uri appears to be the correct value: /storage/emulated/0/DCIM/steprock
Can anyone spot the code error? A partial listing is below:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final VideoView videoView = (VideoView) findViewById(R.id.video_view);
String videoName1 = Environment.getExternalStorageDirectory().getPath()+"/DCIM/steprock";
Uri videoUri = Uri.parse(videoName1);
videoView.setVideoURI(videoUri);
//videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.steprock));
This is code which play video from path you describe for video in VideoView.
// Video path.
path = Environment.getExternalStorageDirectory().getPath()+"/DCIM/steprock.mp4";
videoView = (VideoView) findViewById(R.id.video_view);
final MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri uri = Uri.parse(path);
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
I found the error, forgot to add the read permission below to the manifest:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<application ...
I am trying to build an app to play video from an URL, I am using rtsp, I have tried with most of the examples that I have found online, however none has worked.. This is my code so far in the client:
package com.example.rtsp_player;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String uri = "rtsp://192.168.2.170:5544/";
VideoView v = (VideoView) findViewById( R.id.videoView );
v.setVideoURI( Uri.parse(uri) );
v.setMediaController( new MediaController( this ) );
v.requestFocus();
v.start();
}
}
And this is how I am broadcasting using vlc:
:sout=#transcode{vcodec=h264,vb=800,fps=30,width=320,height=180,acodec=mp4a,ab=128,channels=2,samplerate=22050} :rtp{sdp=rtsp://192.168.2.170:5544/}**
I don't know if it is because of the codecs or what..
myVideoView = (VideoView) findViewById(R.id.myview);
myVideoView.setVideoPath("rtsp://SERVER_IP_ADDR:5544/");
myVideoView.setMediaController(new MediaController(this));
this may help
Add this line to your code.
Uri uri = Uri.withAppendedPath(MediaStore.Video.Media.INTERNAL_CONTENT_URI,"1");
Change the code like this and try.
String uri = "rtsp://192.168.2.170:5544/";
VideoView v = (VideoView) findViewById( R.id.videoView );
Uri uri_add = Uri.withAppendedPath(MediaStore.Video.Media.INTERNAL_CONTENT_URI,"1");
v.setVideoURI( uri_add.parse(uri) );
v.setMediaController( new MediaController( this ) );
v.requestFocus();
v.start();
I want to play a video from res/raw in android here is my code:
public class CreditsActivity extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.creditslayout);
VideoView v = (VideoView) findViewById(R.id.video);
v.setVideoURI(Uri.parse("android.resource://test.test.test/raw/maincredits"));
v.start();
}
}
But I hear only the sound of video. And the emulator doesn't show the video itself the size of file is 2.8 MB.
Try below code :
public class CreditsActivity extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.creditslayout);
VideoView v = (VideoView) findViewById(R.id.video);
v.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video_file));
v.start();
}
}
Please try this.
Uri uri = Uri.parse("android.resource://test.test.test/"+R.raw.[video_resid]);
v.setVideoURI(uri);
try Uri.parse("android.resource://test.test.test/" + R.raw.yourVideoName)
Try this
// trailer_final is the video name
String fileName = "android.resource://"+ getPackageName()+"/raw/trailer_final";
VideoView mvideo = (VideoView) findViewById(R.id.playVideo);
mvideo.setVideoPath(fileName);
MediaController controller = new MediaController(this);
mvideo.setMediaController(controller);
mvideo.requestFocus();
mvideo.start();
Try this:
VideoView view = (VideoView)findViewById(R.id.videoView);
String path = "android.resource://" + getPackageName() + "/" + R.raw.video_file;
view.setVideoURI(Uri.parse(path));
view.start();
Just pass the name of the video residing in the raw folder under res of the project.
The emulator doesn't show the video. I had this problem on a project. We tried it on an actual device and it played perfectly. Try to play it on actual device. It will likely work.
I am making simple videoview app from this link
http://www.androidpeople.com/android-videoview-example
Now what should be the Uri here, i mean should i write path like:
"C:\Folder 1\file.mp4"
I am usin mp4 file from :
http://www.mp4mobi.com/mp41315287045/Swept_Away_Bride.htm
see this example code
package com.video.tab;
import android.app.Activity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class VideoPlayActivity extends Activity {
public void onCreate(Bundle bundle){
super.onCreate(bundle);
setContentView(R.layout.video);
VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
final MediaController mc = new MediaController(this);
videoView.setMediaController(new MediaController(this){
/*public void hide()
{
mc.show();
}*/
});
//videoView.setVideoURI(Uri.parse("http://www.androidbook.com/akc/filestorage/android/documentfiles/3389/movie.mp4"));
videoView.setVideoPath("/sdcard/rabbit-and-snail.3gp");
videoView.requestFocus();
videoView.start();
}
}
in this ,uri locates the path of the ur video file.
Add the video file to your sdcard.
Use:
Uri.parse("file:/sdcard/videofilename")
Should work.
You can't Add File From your PC you have to put that .MP4 file to Raw folder or in your asset Folder....
1st you Create Folder in Application's resource with Name = raw.
After That put file in raw folder...
And than use this Code...
VideoView videoHolder = (VideoView) findViewById(R.id.web_Video);
Uri videoUri = Uri.parse("android.resource://" + getPackageName() + "/"
+ R.raw.data);