Android Open Source - edu-video-client Video View Activity






From Project

Back to project page edu-video-client.

License

The source code is released under:

Apache License

If you think the Android project edu-video-client listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ngm.explaintome;
/*from   w w  w.  j a  va  2 s.c  o m*/
import java.util.Arrays;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

import com.ngm.explaintome.YoutubeUrlAsyncTask.VideoTaskListener;
import com.ngm.explaintome.data.Answer;
import com.ngm.explaintome.data.Question;
import com.ngm.explaintome.service.Callback;
import com.ngm.explaintome.service.MockRestActions;
import com.ngm.explaintome.service.RestActions;

public class VideoViewActivity extends Activity implements VideoTaskListener {

  private VideoView videoView;

  private RestActions restActions;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video_view);

    videoView = (VideoView) findViewById(R.id.video_view);

    restActions = new MockRestActions();

    final YoutubeUrlAsyncTask task = new YoutubeUrlAsyncTask(this);

    Intent intent = getIntent();
    String name = intent.getStringExtra("title");

    task.execute("https://www.youtube.com/watch?v=zyEednV9A94");

    final MediaController controller = new MediaController(this);
    controller.setMediaPlayer(videoView);
    controller.setAnchorView(videoView);

    videoView.setMediaController(controller);
  }

  private void showDialog(final String title, final CharSequence[] items,
      final List<Question> questions, final int questionIndex,
      final int videoPosition) {
    final AlertDialog.Builder ad = new AlertDialog.Builder(
        VideoViewActivity.this);
    ad.setTitle(title);
    ad.setSingleChoiceItems(items, -1,
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int position) {

            Toast.makeText(getApplicationContext(),
                "You Chose : " + items[position],
                Toast.LENGTH_LONG).show();
            dialog.cancel();
            videoView.start();
            startNextQuestion(questions, questionIndex,
                videoPosition);
          }
        });
    videoView.pause();
    ad.show();
  }

  private void startNextQuestion(final List<Question> questions,
      final int index, final int videoTime) {
    if (index >= questions.size()) {
      return;
    }
    final Question question = questions.get(index);
    videoView.postDelayed(new Runnable() {

      @Override
      public void run() {
        String[] items = new String[question.getAnswers().size()];
        final List<Answer> answers = question.getAnswers();
        for (int i = 0; i < answers.size(); ++i) {
          items[i] = answers.get(i).getText();
        }

        showDialog(question.getText(), items, questions, index + 1,
            videoView.getCurrentPosition());
      }

    }, question.getTimestamp() - videoTime);
  }

  @Override
  public void onUrlRetrieved(String url) {
    videoView.setVideoURI(Uri.parse(url));
    videoView.start();
    videoView.setOnPreparedListener(new OnPreparedListener() {

      @Override
      public void onPrepared(final MediaPlayer mp) {
        restActions.getQuestions(null, new Callback<List<Question>>() {

          @Override
          public void call(final List<Question> questions) {
            if (questions.isEmpty()) {
              return;
            }

            final Question question = questions.get(0);
            videoView.postDelayed(new Runnable() {

              @Override
              public void run() {
                String[] items = new String[question
                    .getAnswers().size()];
                final List<Answer> answers = question
                    .getAnswers();
                for (int i = 0; i < answers.size(); ++i) {
                  items[i] = answers.get(i).getText();
                }

                showDialog(question.getText(), items,
                    questions, 1,
                    videoView.getCurrentPosition());
              }

            }, question.getTimestamp());
          }
        });
      }
    });
  }
}




Java Source Code List

com.ngm.exlpaintome.video.VideoControllerView.java
com.ngm.explaintome.BaseActivity.java
com.ngm.explaintome.BaseListActivity.java
com.ngm.explaintome.BrowseActivity.java
com.ngm.explaintome.ColoredSearchView.java
com.ngm.explaintome.Constants.java
com.ngm.explaintome.ExplainActivity.java
com.ngm.explaintome.FilterableEntity.java
com.ngm.explaintome.FirstActivity.java
com.ngm.explaintome.FixedPagerAdapter.java
com.ngm.explaintome.RestConfig.java
com.ngm.explaintome.VideoViewActivity.java
com.ngm.explaintome.VideosActivity.java
com.ngm.explaintome.YoutubeUrlAsyncTask.java
com.ngm.explaintome.data.Answer.java
com.ngm.explaintome.data.ModelElement.java
com.ngm.explaintome.data.QuestionType.java
com.ngm.explaintome.data.Question.java
com.ngm.explaintome.data.Tag.java
com.ngm.explaintome.data.Video.java
com.ngm.explaintome.modules.ModuleProvider.java
com.ngm.explaintome.service.Callback.java
com.ngm.explaintome.service.MockRestActions.java
com.ngm.explaintome.service.RestActionsImpl.java
com.ngm.explaintome.service.RestActions.java