Esempio n. 1
0
        public void onPrepared(MediaPlayer mp) {
          mCurrentState = STATE_PREPARED;
          // modify by lxj
          // Get the capabilities of the player for this stream
          //            Metadata data = mp.getMetadata(MediaPlayer.METADATA_ALL,
          //                                      MediaPlayer.BYPASS_METADATA_FILTER);
          //
          //            if (data != null) {
          //                mCanPause = !data.has(Metadata.PAUSE_AVAILABLE)
          //                        || data.getBoolean(Metadata.PAUSE_AVAILABLE);
          //                mCanSeekBack = !data.has(Metadata.SEEK_BACKWARD_AVAILABLE)
          //                        || data.getBoolean(Metadata.SEEK_BACKWARD_AVAILABLE);
          //                mCanSeekForward = !data.has(Metadata.SEEK_FORWARD_AVAILABLE)
          //                        || data.getBoolean(Metadata.SEEK_FORWARD_AVAILABLE);
          //            } else {
          //                mCanPause = mCanSeekBack = mCanSeekForward = true;
          //            }
          mCanPause = mCanSeekBack = mCanSeekForward = true;

          if (mOnPreparedListener != null) {
            mOnPreparedListener.onPrepared(mMediaPlayer);
          }
          if (mMediaController != null) {
            mMediaController.setEnabled(true);
          }
          mVideoWidth = mp.getVideoWidth();
          mVideoHeight = mp.getVideoHeight();

          int seekToPosition =
              mSeekWhenPrepared; // mSeekWhenPrepared may be changed after seekTo() call
          if (seekToPosition != 0) {
            seekTo(seekToPosition);
          }
          if (mVideoWidth != 0 && mVideoHeight != 0) {
            // Log.i("@@@@", "video size: " + mVideoWidth +"/"+ mVideoHeight);
            getHolder().setFixedSize(mVideoWidth, mVideoHeight);
            if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) {
              // We didn't actually change the size (it was already at the size
              // we need), so we won't get a "surface changed" callback, so
              // start the video here instead of in the callback.
              if (mTargetState == STATE_PLAYING) {
                start();
                if (mMediaController != null) {
                  mMediaController.show();
                }
              } else if (!isPlaying() && (seekToPosition != 0 || getCurrentPosition() > 0)) {
                if (mMediaController != null) {
                  // Show the media controls when we're paused into a video and make 'em stick.
                  mMediaController.show(0);
                }
              }
            }
          } else {
            // We don't know the video size yet, but should start anyway.
            // The video size might be reported to us later.
            if (mTargetState == STATE_PLAYING) {
              start();
            }
          }
        }
Esempio 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);
 }
Esempio n. 3
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);
 }
Esempio n. 5
0
 public void onPrepared(MediaPlayer mp) {
   // briefly show the mediacontroller
   mIsPrepared = true;
   if (mOnPreparedListener != null) {
     mOnPreparedListener.onPrepared(mMediaPlayer);
   }
   if (mMediaController != null) {
     mMediaController.setEnabled(true);
   }
   mVideoWidth = mp.getVideoWidth();
   mVideoHeight = mp.getVideoHeight();
   if (mVideoWidth != 0 && mVideoHeight != 0) {
     // Log.i("@@@@", "video size: " + mVideoWidth +"/"+
     // mVideoHeight);
     getHolder().setFixedSize(mVideoWidth, mVideoHeight);
     if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) {
       // We didn't actually change the size (it was already at the
       // size
       // we need), so we won't get a "surface changed" callback,
       // so
       // start the video here instead of in the callback.
       if (mSeekWhenPrepared != 0) {
         mMediaPlayer.seekTo(mSeekWhenPrepared);
         mSeekWhenPrepared = 0;
       }
       if (mStartWhenPrepared) {
         mMediaPlayer.start();
         mStartWhenPrepared = false;
         if (mMediaController != null) {
           mMediaController.show();
         }
       } else if (!isPlaying() && (mSeekWhenPrepared != 0 || getCurrentPosition() > 0)) {
         if (mMediaController != null) {
           // Show the media controls when we're paused into a
           // video and make 'em stick.
           mMediaController.show(0);
         }
       }
     }
   } else {
     // We don't know the video size yet, but should start anyway.
     // The video size might be reported to us later.
     if (mSeekWhenPrepared != 0) {
       mMediaPlayer.seekTo(mSeekWhenPrepared);
       mSeekWhenPrepared = 0;
     }
     if (mStartWhenPrepared) {
       mMediaPlayer.start();
       mStartWhenPrepared = false;
     }
   }
 }
Esempio n. 6
0
 public void onPrepared(MediaPlayer mp) {
   // briefly show the mediacontroller
   mIsPrepared = true;
   if (mOnPreparedListener != null) {
     mOnPreparedListener.onPrepared(mMediaPlayer);
   }
   if (mMediaController != null) {
     mMediaController.setEnabled(true);
   }
   mVideoWidth = mp.getVideoWidth();
   mVideoHeight = mp.getVideoHeight();
   if (mVideoWidth != 0 && mVideoHeight != 0) {
     // Log.i("@@@@", "video size: " + mVideoWidth +"/"+ mVideoHeight);
     getHolder().setFixedSize(mVideoWidth, mVideoHeight);
     if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) {
       // We didn't actually change the size (it was already at the size
       // we need), so we won't get a "surface changed" callback, so
       // start the video here instead of in the callback.
       if (mSeekWhenPrepared != 0) {
         mMediaPlayer.seekTo(mSeekWhenPrepared);
       }
       if (mStartWhenPrepared) {
         mMediaPlayer.start();
         if (mMediaController != null) {
           mMediaController.show();
         }
       } else if (!isPlaying() && (mSeekWhenPrepared != 0 || getCurrentPosition() > 0)) {
         if (mMediaController != null) {
           mMediaController.show(
               0); // show the media controls when we're paused into a video and make 'em
           // stick.
         }
       }
     }
   } else {
     Log.d(
         "VideoView",
         "Couldn't get video size after prepare(): " + mVideoWidth + "/" + mVideoHeight);
     // The file was probably truncated or corrupt. Start anyway, so
     // that we play whatever short snippet is there and then get
     // the "playback completed" event.
     if (mStartWhenPrepared) {
       mMediaPlayer.start();
     }
   }
 }
Esempio n. 7
0
        public void onPrepared(MediaPlayer mp) {
          mCurrentState = STATE_PREPARED;

          if (mOnPreparedListener != null) {
            mOnPreparedListener.onPrepared(mMediaPlayer);
          }
          if (mMediaController != null) {
            mMediaController.setEnabled(true);
          }
          mVideoWidth = mp.getVideoWidth();
          mVideoHeight = mp.getVideoHeight();

          int seekToPosition =
              mSeekWhenPrepared; // mSeekWhenPrepared may be changed after seekTo() call
          if (seekToPosition != 0) {
            seekTo(seekToPosition);
          }
          if (mVideoWidth != 0 && mVideoHeight != 0) {
            // Log.i("@@@@", "video size: " + mVideoWidth +"/"+ mVideoHeight);
            getHolder().setFixedSize(mVideoWidth, mVideoHeight);
            if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) {
              // We didn't actually change the size (it was already at the size
              // we need), so we won't get a "surface changed" callback, so
              // start the video here instead of in the callback.
              if (mTargetState == STATE_PLAYING) {
                start();
                if (mMediaController != null) {
                  mMediaController.show();
                }
              } else if (!isPlaying() && (seekToPosition != 0 || getCurrentPosition() > 0)) {
                if (mMediaController != null) {
                  // Show the media controls when we're paused into a video and make 'em stick.
                  mMediaController.show(0);
                }
              }
            }
          } else {
            // We don't know the video size yet, but should start anyway.
            // The video size might be reported to us later.
            if (mTargetState == STATE_PLAYING) {
              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);
  }
Esempio n. 9
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();
  }
  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);
  }
 public void onCreate(Bundle paramBundle)
 {
   super.onCreate(paramBundle);
   setDefaultKeyMode(2);
   getWindow().setFlags(2000, 1024);
   setContentView(2130903380);
   p = new kl(this, this);
   m = ((ESVideoView)findViewById(2131625376));
   o = ((FrameLayout)findViewById(2131625377));
   o.setOnClickListener(new km(this));
   D = ((TextView)findViewById(2131625378));
   D.setText(getString(2131232491) + getString(2131231155));
   m.setMediaController(p);
   try
   {
     p.setEnabled(false);
     p.requestFocus();
     m.setOnCompletionListener(new kn(this));
     m.setOnErrorListener(new ko(this));
     m.setOnPreparedListener(new jh(this));
     m.setSeekListener(new ji(this));
     u = getIntent().getData();
     if ((ac.a() < 8) && (e())) {
       finish();
     }
     for (;;)
     {
       return;
       t = 0;
       g = false;
       if (com.estrongs.android.pop.view.a.a.startsWith("Spreadtrum")) {}
       try
       {
         registerReceiver(K, new IntentFilter("android.intent.action.SCREEN_OFF"));
         registerReceiver(L, new IntentFilter("android.intent.action.USER_PRESENT"));
         registerReceiver(M, new IntentFilter("android.intent.action.ACTION_SHUTDOWN"));
         b = findViewById(2131624351);
         w = c.a(this);
         if (!getIntent().getBooleanExtra("islocalopen", false)) {}
         try
         {
           w.d("act3");
           w.a("act3", "video_player");
           x = findViewById(2131625379);
           y = ((TextView)x.findViewById(2131625380));
           paramBundle = getIntent().getData();
           v = a(paramBundle);
           if (v != null) {
             y.setText(ap.d(v));
           }
           View localView = x;
           if (p.isShown())
           {
             i1 = 0;
             localView.setVisibility(i1);
             d = x.findViewById(2131625031);
             d.setOnClickListener(new jj(this));
             z = findViewById(2131624418);
             z.setOnClickListener(new jk(this));
             findViewById(2131625030).setOnClickListener(new jl(this));
             m.setVideoURI(paramBundle);
             if (n) {
               continue;
             }
             if (!getIntent().getBooleanExtra("Chromecast", false)) {
               break label648;
             }
             h();
             if (getIntent().getStringExtra("ChromecastUrl") != null) {
               a(true);
             }
             if (!a()) {
               continue;
             }
             if (!p.isShown()) {
               f();
             }
             new jm(this).start();
             return;
           }
         }
         catch (Exception paramBundle)
         {
           for (;;)
           {
             paramBundle.printStackTrace();
             continue;
             int i1 = 4;
             continue;
             label648:
             p();
             r();
           }
         }
       }
       catch (Exception paramBundle)
       {
         for (;;) {}
       }
     }
   }
   catch (Exception paramBundle)
   {
     for (;;) {}
   }
 }
  @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);
    }
  }
Esempio n. 13
0
 @Override
 public void setEnabled(boolean enabled) {
   mMediaController.setEnabled(enabled);
 }