Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seek to time in video feature. and duration returning on video closed #222

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@ cordova plugin add https://github.com/nchutchind/cordova-plugin-streaming-media

// Play a video with callbacks
var options = {
successCallback: function() {
successCallback: function(res) {
console.log("Video was closed without error.");
console.log(res); // {"duration":"19641"} a json returned for resume video later if req
},
errorCallback: function(errMsg) {
console.log("Error! " + errMsg);
console.log(errMsg);
// {"duration":"19641","message": "Error Message"} a json content
},
orientation: 'landscape',
shouldAutoClose: true, // true(default)/false
controls: true // true(default)/false. Used to hide controls on fullscreen
controls: true,// true(default)/false. Used to hide controls on fullscreen
start: 0// Seekto in miliseconds 0(Default)/ time in miliseconds (Android Only)
};
window.plugins.streamingMedia.playVideo(videoUrl, options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.VideoView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class SimpleVideoStream extends Activity implements
MediaPlayer.OnCompletionListener, MediaPlayer.OnPreparedListener,
Expand All @@ -30,6 +33,7 @@ public class SimpleVideoStream extends Activity implements
private MediaController mMediaController = null;
private ProgressBar mProgressBar = null;
private String mVideoUrl;
private String start;
private Boolean mShouldAutoClose = true;
private boolean mControls;

Expand All @@ -38,9 +42,10 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
Bundle b = getIntent().getExtras();
mVideoUrl = b.getString("mediaUrl");
start = b.getString("start",0);
mShouldAutoClose = b.getBoolean("shouldAutoClose", true);
mControls = b.getBoolean("controls", true);

Expand Down Expand Up @@ -120,6 +125,7 @@ public void onPrepared(MediaPlayer mp) {
mMediaPlayer.setOnBufferingUpdateListener(this);
mVideoView.requestFocus();
mVideoView.start();
mVideoView.seekTo(Integer.valueOf(start));
mVideoView.postDelayed(checkIfPlaying, 0);
}

Expand All @@ -143,7 +149,16 @@ public void onDestroy() {
private void wrapItUp(int resultCode, String message) {
Log.d(TAG, "wrapItUp was triggered.");
Intent intent = new Intent();
intent.putExtra("message", message);

JSONObject dataToSend = new JSONObject();
try {
dataToSend.put("duration", String.valueOf(mVideoView.getCurrentPosition()));
dataToSend.put("message", message);
} catch (Exception e) {
e.printStackTrace();
}

intent.putExtra("message", dataToSend.toString());
setResult(resultCode, intent);
finish();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void run() {
final Intent streamIntent = new Intent(cordovaObj.getActivity().getApplicationContext(), activityClass);
Bundle extras = new Bundle();
extras.putString("mediaUrl", url);

if (options != null) {
Iterator<String> optKeys = options.keys();
while (optKeys.hasNext()) {
Expand Down Expand Up @@ -93,15 +93,15 @@ public void run() {
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
Log.v(TAG, "onActivityResult: " + requestCode + " " + resultCode);
super.onActivityResult(requestCode, resultCode, intent);
String message = "";
if (intent != null && intent.hasExtra("message")) {
message = intent.getStringExtra("message");
}
if (ACTIVITY_CODE_PLAY_MEDIA == requestCode) {
if (Activity.RESULT_OK == resultCode) {
this.callbackContext.success();
this.callbackContext.success(message);
} else if (Activity.RESULT_CANCELED == resultCode) {
String errMsg = "Error";
if (intent != null && intent.hasExtra("message")) {
errMsg = intent.getStringExtra("message");
}
this.callbackContext.error(errMsg);
this.callbackContext.error(message);
}
}
}
Expand Down