Created
May 30, 2016 01:41
-
-
Save eneim/d3cf8e26da01fd3073db0f49bfdc3b87 to your computer and use it in GitHub Desktop.
Sample activity to reproduce ScaleType's wrong result on ExoMedia library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Copyright 2016 Nam Nguyen, nam@ene.im | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| package im.ene.lab.flvv.sample.features.standalone; | |
| import android.os.Bundle; | |
| import android.support.annotation.Nullable; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.view.View; | |
| import android.widget.Button; | |
| import com.devbrackets.android.exomedia.core.video.scale.ScaleType; | |
| import com.devbrackets.android.exomedia.listener.OnPreparedListener; | |
| import com.devbrackets.android.exomedia.ui.widget.EMVideoView; | |
| import im.ene.lab.flvv.sample.R; | |
| import im.ene.lab.flvv.sample.data.repository.VideosRepo; | |
| /** | |
| * Created by eneim on 5/19/16. | |
| */ | |
| public class StandalonePlayerActivity extends AppCompatActivity { | |
| private EMVideoView videoView; | |
| private Button changeScaleTypeButton; | |
| private Button changeVideo; | |
| final ScaleType[] SCALE_TYPES = { | |
| ScaleType.FIT_CENTER, | |
| ScaleType.CENTER, ScaleType.CENTER_CROP, ScaleType.CENTER_INSIDE | |
| }; | |
| int scaleTypeIndex = 0; | |
| int videoIndex = 0; | |
| @Override protected void onCreate(@Nullable Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| videoView = (EMVideoView) findViewById(R.id.video_view); | |
| changeScaleTypeButton = (Button) findViewById(R.id.scale_button); | |
| changeVideo = (Button) findViewById(R.id.change_video); | |
| scaleType = SCALE_TYPES[scaleTypeIndex % SCALE_TYPES.length]; | |
| videoView.setScaleType(scaleType); | |
| videoView.setOnPreparedListener(new OnPreparedListener() { | |
| @Override public void onPrepared() { | |
| videoView.start(); | |
| } | |
| }); | |
| //videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { | |
| // @Override public void onPrepared(MediaPlayer mp) { | |
| // if (videoView != null) { | |
| // videoView.start(); | |
| // } | |
| // } | |
| //}); | |
| changeScaleTypeButton.setText("SCALE TYPE: " + getCurrentScaleType().name()); | |
| changeScaleTypeButton.setOnClickListener(new View.OnClickListener() { | |
| @Override public void onClick(View v) { | |
| scaleType = SCALE_TYPES[++scaleTypeIndex % SCALE_TYPES.length]; | |
| videoView.setScaleType(scaleType); | |
| changeScaleTypeButton.setText("SCALE TYPE: " + getCurrentScaleType().name()); | |
| } | |
| }); | |
| changeVideo.setOnClickListener(new View.OnClickListener() { | |
| @Override public void onClick(View v) { | |
| videoView.setVideoPath(VideosRepo.VIDEO_URIS[++videoIndex % VideosRepo.VIDEO_URIS.length]); | |
| } | |
| }); | |
| } | |
| @Override protected void onResume() { | |
| super.onResume(); | |
| videoView.setVideoPath(VideosRepo.VIDEO_URIS[videoIndex % VideosRepo.VIDEO_URIS.length]); | |
| } | |
| @Override protected void onPause() { | |
| super.onPause(); | |
| videoView.stopPlayback(); | |
| } | |
| private ScaleType scaleType = ScaleType.FIT_CENTER; | |
| ScaleType getCurrentScaleType() { | |
| return scaleType; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment