Ejemplo n.º 1
0
 private void prepareToStart(Track dataSource) {
   try {
     if (dataSource.isVideo()) {
       mediaController.setMediaPlayer(mVideoView);
       mVideoView.setVisibility(VideoView.VISIBLE);
       mVideoView.setVideoPath(dataSource.getPath());
       mVideoView.start();
     } else {
       mediaPlayer.reset();
       mVideoView.setVisibility(VideoView.INVISIBLE);
       mediaPlayer.setDataSource(dataSource.getPath());
       mediaPlayer.prepare();
       mediaPlayer.start();
     }
     ((TextView) findViewById(R.id.now_playing_text))
         .setText(currentPlaylist.getCurrent().getTitle());
   } catch (IllegalArgumentException e) {
     e.printStackTrace();
   } catch (SecurityException e) {
     e.printStackTrace();
   } catch (IllegalStateException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 2
0
 private void preparePlayer(boolean playWhenReady) {
   if (player == null) {
     player = new DemoPlayer(getRendererBuilder());
     player.addListener(this);
     player.setCaptionListener(this);
     player.setMetadataListener(this);
     player.seekTo(playerPosition);
     playerNeedsPrepare = true;
     mediaController.setMediaPlayer(player.getPlayerControl());
     mediaController.setEnabled(true);
     eventLogger = new EventLogger();
     eventLogger.startSession();
     player.addListener(eventLogger);
     player.setInfoListener(eventLogger);
     player.setInternalErrorListener(eventLogger);
     debugViewHelper = new DebugTextViewHelper(player, debugTextView);
     debugViewHelper.start();
   }
   if (playerNeedsPrepare) {
     player.prepare();
     playerNeedsPrepare = false;
     updateButtonVisibilities();
   }
   player.setSurface(surfaceView.getHolder().getSurface());
   player.setPlayWhenReady(playWhenReady);
 }
 private void h()
 {
   if (!B.p())
   {
     l.e(k, "changeToCastMode error, chromecast is not connected");
     return;
   }
   if (p != null) {
     p.hide();
   }
   m();
   A = 1;
   o.setVisibility(0);
   if (q == null)
   {
     q = new kk(this, this);
     if (r == null)
     {
       r = new kt(this);
       B.a(r);
       B.a(r);
       B.a(r);
     }
     q.setMediaPlayer(r);
     q.setAnchorView(o);
   }
   ((ImageView)z.findViewById(2131624054)).setImageResource(2130838531);
   if ((B.r() > 0) && (B.r() != 2)) {
     b.setVisibility(0);
   }
   J.sendMessageDelayed(J.obtainMessage(5), 1000L);
 }
  @Override
  public void onPrepared(MediaPlayer mp) {
    mediaPlayer.start();
    mediacontroller.setMediaPlayer(this);
    mediacontroller.setAnchorView(findViewById(R.id.surfaceView));

    mediacontroller.show();
  }
Ejemplo n.º 5
0
 private void attachMediaController() {
   if (mMediaPlayer != null && mMediaController != null) {
     mMediaController.setMediaPlayer(this);
     View anchorView = this.getParent() instanceof View ? (View) this.getParent() : this;
     mMediaController.setAnchorView(anchorView);
     mMediaController.setEnabled(mIsPrepared);
   }
 }
 @Override
 public void onResume() {
   super.onResume();
   mPlayer = ExoPlayer.Factory.newInstance(2, 1000, 5000);
   mPlayer.addListener(this);
   mPlayer.seekTo(mPlayerPosition);
   mMediaController.setMediaPlayer(new PlayerControl(mPlayer));
   mMediaController.setEnabled(true);
   mCallback = new RendererBuilderCallback();
   mBuilder.buildRenderers(mCallback);
 }
Ejemplo n.º 7
0
 @Override
 public void onPrepared(MediaPlayer mediaPlayer) {
   mediaController.setMediaPlayer(this);
   mediaController.setAnchorView(findViewById(R.id.main_audio_view));
   handler.post(
       new Runnable() {
         public void run() {
           mediaController.setEnabled(true);
           mediaController.show();
         }
       });
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().setWindowAnimations(0); // Do not animate the view when it gets pushed on the screen
    setContentView(R.layout.videoview);

    CustomApp appState = ((CustomApp) getApplicationContext());
    unzippedDir = appState.getUnzippedDir();
    // videoView =  (VideoView) findViewById(R.id.surface_view); //new VideoView(VideoViewer.this);

    // Get the extras (video filename) out of the new intent
    Intent intent = getIntent();
    if (intent != null) videoFile = intent.getStringExtra("video");
    if (intent != null) packagePath = intent.getStringExtra("path");

    File clip = new File(/*unzippedDir + */ packagePath + File.separator + videoFile);
    System.out.println("Complete video path === " + packagePath + File.separator + videoFile);

    try {
      if (clip.exists()) {

        videoView = new VideoView(VideoViewer.this);
        videoView.setVideoPath(clip.getAbsolutePath());

        videoView.setLayoutParams(
            new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

        ctlr = new MediaController(VideoViewer.this);
        ctlr.setMediaPlayer(videoView);
        videoView.setMediaController(ctlr);
        videoView.requestFocus();
        videoView.start();
        setContentView(videoView);

      } else {
        TextView tv = new TextView(this);
        tv.setText("File does not exist");
        setContentView(tv);
      }
    } catch (OutOfMemoryError E) {
      // Release some (all) of the above objects
      System.out.println("Out of Memory Exception");
      TextView txtView = new TextView(VideoViewer.this);
      txtView.setText("Error: Out of Memory - video file is too big to load!");
      setContentView(txtView);
    }
  }
Ejemplo n.º 9
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    v = (VideoView) findViewById(R.id.videoView);
    MediaController ctrlr;
    String url = "http://techslides.com/demos/sample-videos/small.mp4";
    v.setVideoURI(Uri.parse("http://techslides.com/demos/sample-videos/small.mp4"));

    ctrlr = new MediaController(this);
    v.setOnCompletionListener(this);
    ctrlr.setAnchorView(v);
    ctrlr.setMediaPlayer(v);
    v.setMediaController(ctrlr);
    v.requestFocus();
    v.start();
  }
  private void preparePlayer() {

    if (player == null) {
      String userAgent = Util.getUserAgent(this, "ExoPlayerDemo");
      player =
          new DemoPlayer(
              new HlsRendererBuilder(
                  this, userAgent, VIDEO_URL.toString(), null, audioCapabilities));
      player.addListener(this);
      player.seekTo(playerPosition);
      playerNeedsPrepare = true;
      mediaController.setMediaPlayer(player.getPlayerControl());
      mediaController.setEnabled(true);
    }
    if (playerNeedsPrepare) {
      player.prepare();
      playerNeedsPrepare = false;
      updateButtonVisibilities();
    }
    player.setSurface(surfaceView.getHolder().getSurface());
    player.setPlayWhenReady(true);
  }
Ejemplo n.º 11
0
  public void onPrepared(MediaPlayer mp) {
    Log.v(LOGTAG, "onPrepared Called");
    videoWidth = mp.getVideoWidth();
    videoHeight = mp.getVideoHeight();

    // 스크린 사이즈 구하기
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int screenWidth = metrics.widthPixels;
    int screenHeight = metrics.heightPixels;

    if (videoWidth > screenWidth || videoHeight > screenHeight) {
      float heightRatio = (float) videoHeight / (float) screenHeight;
      float widthRatio = (float) videoWidth / (float) screenWidth;

      if (heightRatio > 1 || widthRatio > 1) {
        if (heightRatio > widthRatio) {
          videoHeight = (int) Math.ceil((float) videoHeight / (float) heightRatio);
          videoWidth = (int) Math.ceil((float) videoWidth / (float) heightRatio);
        } else {
          videoHeight = (int) Math.ceil((float) videoHeight / (float) widthRatio);
          videoWidth = (int) Math.ceil((float) videoWidth / (float) widthRatio);
        }
      }
    } else {
      videoHeight = screenHeight;
      videoWidth = screenWidth;
    }

    // surfaceView.setLayoutParams(new FrameLayout.LayoutParams(videoWidth,
    // videoHeight - 75));
    mp.start();

    // 미디어 플레이어의 컨트롤러를 설정하고 보이기
    controller.setMediaPlayer(this);
    controller.setAnchorView(this.findViewById(R.id.controllerView));
    controller.setEnabled(true);
    controller.show();
  }
Ejemplo n.º 12
0
  private void preparePlayer() {
    // TODO(cartland): Remove sample video.
    String url =
        "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/April%20Fool's%202013/Introducing%20Google%20Fiber%20to%20the%20Pole.mp4";
    mVideo.setContentUrl(url);

    SampleSource sampleSource =
        new FrameworkSampleSource(
            this, Uri.parse(mVideo.getContentUrl()), /* headers */ null, RENDERER_COUNT);

    // Build the track renderers
    videoRenderer =
        new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
    TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);

    // Setup the player
    player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
    player.addListener(this);
    // Build the player controls
    mediaController.setMediaPlayer(new PlayerControl(player));
    mediaController.setEnabled(true);
    player.prepare(videoRenderer, audioRenderer);
  }
Ejemplo n.º 13
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video3);
    vv_video = (VideoView) findViewById(R.id.vv_video);
    // 实例化MediaController
    mController = new MediaController(this);
    //
    // File file = new File(pathString);
    // if (file.exists()) {
    // 设置播放视频源的路径
    // vv_video.setVideoPath(file.getAbsolutePath());

    vv_video.setVideoURI(Uri.parse(pathString));

    // 为VideoView指定MediaController
    vv_video.setMediaController(mController);
    // 为MediaController指定控制的VideoView
    mController.setMediaPlayer(vv_video);
    // 增加监听上一个和下一个的切换事件,默认这两个按钮是不显示的
    mController.setPrevNextListeners(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            Toast.makeText(VedioPlay3.this, "下一个", Toast.LENGTH_LONG).show();
          }
        },
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            Toast.makeText(VedioPlay3.this, "上一个", Toast.LENGTH_LONG).show();
          }
        });
    // }
  }
Ejemplo n.º 14
0
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_video_play);
   video = (VideoView) findViewById(R.id.video);
   mediaco = new MediaController(this);
   // VideoView与MediaController进行关联
   video.setVideoURI(Uri.parse("android.resource://com.example.qiulin.traffic/" + R.raw.demo));
   video.setMediaController(mediaco);
   mediaco.setMediaPlayer(video);
   // 让VideiView获取焦点
   video.requestFocus();
   video.start();
   //        play=(Button)findViewById(R.id.button1);
   //        pause=(Button)findViewById(R.id.button2);
   //        stop=(Button)findViewById(R.id.button3);
   //        surface=(SurfaceView)findViewById(R.id.surface);
   //        surfaceHolder=surface.getHolder();   //SurfaceHolder是SurfaceView的控制接口
   //        surfaceHolder.addCallback(this);     //因为这个类实现了SurfaceHolder.Callback接口,所以回调参数直接this
   //        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);  //Surface类型
   //
   //        play.setOnClickListener(new Button.OnClickListener(){
   //            @Override
   //            public void onClick(View v) {
   //                player.start();
   //            }});
   //        pause.setOnClickListener(new Button.OnClickListener(){
   //            @Override
   //            public void onClick(View v) {
   //                player.pause();
   //            }});
   //        stop.setOnClickListener(new Button.OnClickListener(){
   //            @Override
   //            public void onClick(View v) {
   //                player.stop();
   //            }});
 }
Ejemplo n.º 15
0
  @Override
  protected void initView() {
    FrameLayout videoRoot = new FrameLayout(mContext);
    videoRoot.setBackgroundColor(WXResourceUtils.getColor("#ee000000"));

    mVideoView = new WXVideoView(mContext);
    FrameLayout.LayoutParams videoLayoutParams =
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    videoLayoutParams.gravity = Gravity.CENTER;
    mVideoView.setLayoutParams(videoLayoutParams);
    videoRoot.addView(mVideoView);

    mProgressBar = new ProgressBar(mContext);
    FrameLayout.LayoutParams pLayoutParams =
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    mProgressBar.setLayoutParams(pLayoutParams);
    pLayoutParams.gravity = Gravity.CENTER;
    videoRoot.addView(mProgressBar);

    final MediaController controller = new MediaController(mContext);

    controller.setAnchorView(videoRoot);

    mVideoView.setOnErrorListener(
        new MediaPlayer.OnErrorListener() {

          @Override
          public boolean onError(MediaPlayer mp, int what, int extra) {
            if (WXEnvironment.isApkDebugable()) {
              WXLogUtils.d("Video", "onError:" + what);
            }
            mProgressBar.setVisibility(View.GONE);
            mPrepared = false;
            mError = true;

            if (mDomObj.event != null && mDomObj.event.contains(WXEventType.VIDEO_FAIL)) {
              WXSDKManager.getInstance().fireEvent(mInstanceId, getRef(), WXEventType.VIDEO_FAIL);
            }
            return true;
          }
        });

    mVideoView.setOnPreparedListener(
        new MediaPlayer.OnPreparedListener() {

          @Override
          public void onPrepared(MediaPlayer mediaPlayer) {
            if (WXEnvironment.isApkDebugable()) {
              WXLogUtils.d("Video", "onPrepared");
            }
            mProgressBar.setVisibility(View.GONE);
            mPrepared = true;
            if (mAutoPlay) {
              mVideoView.start();
            }
            mVideoView.seekTo(5);
            if (!mStopped) {
              controller.show(3);
            } else {
              controller.hide();
            }
            mStopped = false;
          }
        });

    mVideoView.setOnCompletionListener(
        new MediaPlayer.OnCompletionListener() {

          @Override
          public void onCompletion(MediaPlayer mediaPlayer) {
            if (WXEnvironment.isApkDebugable()) {
              WXLogUtils.d("Video", "onCompletion");
            }
            if (mDomObj.event != null && mDomObj.event.contains(WXEventType.VIDEO_FINISH)) {
              WXSDKManager.getInstance().fireEvent(mInstanceId, getRef(), WXEventType.VIDEO_FINISH);
            }
          }
        });

    mVideoView.setOnVideoPauseListener(
        new WXVideoView.VideoPlayListener() {

          @Override
          public void onPause() {
            if (WXEnvironment.isApkDebugable()) {
              WXLogUtils.d("Video", "onPause");
            }
            if (mDomObj.event != null && mDomObj.event.contains(WXEventType.VIDEO_PAUSE)) {
              WXSDKManager.getInstance().fireEvent(mInstanceId, getRef(), WXEventType.VIDEO_PAUSE);
            }
          }

          @Override
          public void onStart() {
            if (WXEnvironment.isApkDebugable()) {
              WXLogUtils.d("Video", "onStart");
            }

            if (mDomObj.event != null && mDomObj.event.contains(WXEventType.VIDEO_START)) {
              WXSDKManager.getInstance().fireEvent(mInstanceId, getRef(), WXEventType.VIDEO_START);
            }
          }
        });

    mVideoView.setMediaController(controller);
    controller.setMediaPlayer(mVideoView);

    mHost = videoRoot;
  }
 private void j()
 {
   q.setMediaPlayer(r);
   J.sendMessageDelayed(J.obtainMessage(5), 1500L);
 }
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this)) return;

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    extras = getIntent().getExtras();

    // handle extras
    if (extras == null) {
      wrapItUp(RESULT_CANCELED, "Error: No options provided");
    } else {
      if (extras.containsKey("isStreaming")) {
        isStreaming = extras.getBoolean("isStreaming");
      }

      if (extras.containsKey("shouldAutoClose")) {
        mShouldAutoClose = extras.getBoolean("shouldAutoClose");
      }

      mMediaType = extras.getString("type");
      if (mMediaType == null) mMediaType = MEDIA_TYPE_VIDEO;

      mMediaPlayer = new MediaPlayer(this);
      mMediaController = new MediaController(this, !isStreaming);
      mMediaController.setMediaPlayer(this);
      mMediaPlayer.setOnBufferingUpdateListener(this);
      mMediaPlayer.setOnCompletionListener(this);
      mMediaPlayer.setOnErrorListener(this);
      mMediaPlayer.setOnPreparedListener(this);
      mMediaPlayer.setOnVideoSizeChangedListener(this);
      setVolumeControlStream(AudioManager.STREAM_MUSIC);

      RelativeLayout relLayout = new RelativeLayout(this);

      if (extras.containsKey("bgColor")) {
        try {
          bgColor = Color.parseColor(extras.getString("bgColor"));
        } catch (Exception e) {
          Log.v(TAG, "Error parsing color");
          Log.e(TAG, e.toString());
          bgColor = DEFAULT_BG_COLOR;
        }
      }
      relLayout.setBackgroundColor(bgColor);

      RelativeLayout.LayoutParams relLayoutParam =
          new RelativeLayout.LayoutParams(
              RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
      relLayoutParam.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
      mMediaView = new SurfaceView(this);
      mMediaView.setLayoutParams(relLayoutParam);
      relLayout.addView(mMediaView);

      mProgressBar = new ProgressBar(this);
      mProgressBar.setIndeterminate(true);
      mProgressBar.setVisibility(View.VISIBLE);
      RelativeLayout.LayoutParams pblp =
          new RelativeLayout.LayoutParams(
              RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
      pblp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
      mProgressBar.setLayoutParams(pblp);
      relLayout.addView(mProgressBar);
      mProgressBar.bringToFront();

      mMediaController.setAnchorView(relLayout);
      mMediaController.setEnabled(true);
      if (mMediaType.equalsIgnoreCase(MEDIA_TYPE_AUDIO)) {
        mMediaView.setBackgroundColor(bgColor);
        if (extras.containsKey("bgImage")) {
          if (extras.containsKey("bgImageScaleType")) {
            String scaleType = extras.getString("bgImageScaleType");
            if (scaleType.equalsIgnoreCase("fit")) {
              bgImageScaleType = ImageView.ScaleType.FIT_CENTER;
            } else if (scaleType.equalsIgnoreCase("stretch")) {
              bgImageScaleType = ImageView.ScaleType.FIT_XY;
            } else {
              bgImageScaleType = ImageView.ScaleType.CENTER;
            }
          }
          bgImage = new ImageView(this);
          new ImageLoadTask(extras.getString("bgImage"), this).execute(null, null);
          RelativeLayout.LayoutParams bgImageLayoutParam =
              new RelativeLayout.LayoutParams(
                  RelativeLayout.LayoutParams.MATCH_PARENT,
                  RelativeLayout.LayoutParams.MATCH_PARENT);
          bgImageLayoutParam.addRule(RelativeLayout.CENTER_IN_PARENT);
          bgImage.setLayoutParams(bgImageLayoutParam);
          bgImage.setScaleType(bgImageScaleType);
          relLayout.addView(bgImage);
        }
      }
      setContentView(relLayout, relLayoutParam);
      holder = mMediaView.getHolder();
      holder.addCallback(this);
      holder.setFormat(PixelFormat.RGBA_8888);
    }
  }
Ejemplo n.º 18
0
 @Override
 public void setDelegate(Delegate delegate) {
   mMediaController.setMediaPlayer(delegate);
 }