Reputation: 23
I'm trying to open a video in android player from fragment but send me this error
No Activity found to handle Intent
here's the code
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.learn, container, false);
ImageButton mBtn = (ImageButton) rootView.findViewById(R.id.iBtn1);
mBtn.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri video = Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + R.raw.video_1);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, video);
getActivity().startActivity(intent);
}
});
return rootView;
Upvotes: 0
Views: 470
Reputation: 1251
This is how im using it:
public class VideoPlayerActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
FrameLayout container = (FrameLayout) findViewById(R.id.container);
container.setBackgroundColor(Color.BLACK);
VideoView videoView =(VideoView)findViewById(R.id.videoView1);
//Creating MediaController
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(videoView);
Intent intent = getIntent();
String path = intent.getStringExtra(Constants.EXTRA_VIDEO_PATH);
//specify the location of media file
//File imageFileFolder = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), Constants.APP_FOLDER);
//imageFileFolder.mkdir();
// File photoFile = new File(imageFileFolder,
// path);
File photoFile = new File(
path);
Uri uri=Uri.fromFile(photoFile);
//Setting MediaController and URI, then starting the videoView
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
}
I think its not possible with intent to do what you asking for.
Upvotes: 1