-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from brianwernick/exoplayer_1_4_1
Updated ExoPlayer to 1.4.1
- Loading branch information
Showing
7 changed files
with
121 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
84 changes: 84 additions & 0 deletions
84
library/src/main/java/com/devbrackets/android/exomedia/widget/VideoSurfaceView.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (C) 2014 The Android Open Source Project | ||
* | ||
* 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 com.devbrackets.android.exomedia.widget; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.view.SurfaceView; | ||
|
||
/** | ||
* A SurfaceView that resizes itself to match a specified aspect ratio. | ||
*/ | ||
public class VideoSurfaceView extends SurfaceView { | ||
/** | ||
* The surface view will not resize itself if the fractional difference between its default | ||
* aspect ratio and the aspect ratio of the video falls below this threshold. | ||
* <p> | ||
* This tolerance is useful for fullscreen playbacks, since it ensures that the surface will | ||
* occupy the whole of the screen when playing content that has the same (or virtually the same) | ||
* aspect ratio as the device. This typically reduces the number of view layers that need to be | ||
* composited by the underlying system, which can help to reduce power consumption. | ||
*/ | ||
private static final float MAX_ASPECT_RATIO_DEFORMATION_FRACTION = 0.01f; | ||
|
||
private float videoAspectRatio; | ||
|
||
public VideoSurfaceView(Context context) { | ||
super(context); | ||
} | ||
|
||
public VideoSurfaceView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
/** | ||
* Set the aspect ratio that this {@link VideoSurfaceView} should satisfy. | ||
* | ||
* @param widthHeightRatio The width to height ratio. | ||
*/ | ||
public void setAspectRatio(float widthHeightRatio) { | ||
if (this.videoAspectRatio != widthHeightRatio) { | ||
this.videoAspectRatio = widthHeightRatio; | ||
requestLayout(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | ||
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | ||
if (videoAspectRatio == 0) { | ||
// Aspect ratio not set. | ||
return; | ||
} | ||
|
||
int width = getMeasuredWidth(); | ||
int height = getMeasuredHeight(); | ||
float viewAspectRatio = (float) width / height; | ||
float aspectDeformation = videoAspectRatio / viewAspectRatio - 1; | ||
if (Math.abs(aspectDeformation) <= MAX_ASPECT_RATIO_DEFORMATION_FRACTION) { | ||
// We're within the allowed tolerance. | ||
return; | ||
} | ||
|
||
if (aspectDeformation > 0) { | ||
height = (int) (width / videoAspectRatio); | ||
} else { | ||
width = (int) (height * videoAspectRatio); | ||
} | ||
|
||
super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); | ||
} | ||
} |
This file contains 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