Back to project page playground-android-video.
The source code is released under:
This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...
If you think the Android project playground-android-video listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package v.app.Fragments; /*from www .ja va2 s . c om*/ /** * Created by vasanth on 25/03/14. */ import android.app.IntentService; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; import v.app.R; import v.app.Services.UploadService; public class VideoFragment extends Fragment { static final int REQUEST_VIDEO_CAPTURE = 1; Button recordButton, playButton, uploadButton; TextView textVideoUrl; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_video, container, false); recordButton = (Button) rootView.findViewById(R.id.recordButton); playButton = (Button) rootView.findViewById(R.id.playButton); uploadButton = (Button) rootView.findViewById(R.id.uploadButton); textVideoUrl = (TextView) rootView.findViewById(R.id.textVideoUrl); initButton(); return rootView; } private void initButton() { recordButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dispatchTakeVideoIntent(); } }); playButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dispatchPlayVideoIntent(); } }); uploadButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dispatchUploadVideoIntent(); } }); } private void dispatchTakeVideoIntent() { RecorderFragment recorderFragment = new RecorderFragment(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace( R.id.container, recorderFragment); transaction.addToBackStack(null); // Commit the transaction transaction.commit(); } @Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == getActivity().RESULT_OK) { Uri videoUri = intent.getData(); textVideoUrl.setText(videoUri.toString()); } } private void dispatchPlayVideoIntent() { String uri = textVideoUrl.getText().toString(); if (! uri.isEmpty() ) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); startActivity(intent); } } private void dispatchUploadVideoIntent() { String uri = textVideoUrl.getText().toString(); if (! uri.isEmpty() ) { Intent uploadServiceIntent; uploadServiceIntent = new Intent(getActivity(), UploadService.class); uploadServiceIntent.setData(Uri.parse(uri)); getActivity().startService(uploadServiceIntent); } } }