package com.volokh.video_player_manager.ui;
import com.volokh.video_player_manager.Config;
import com.volokh.video_player_manager.utils.Logger;
import ohos.agp.components.AttrSet;
import ohos.agp.graphics.SurfaceOps;
import ohos.agp.graphics.TextureHolder;
import ohos.app.Context;
import ohos.app.dispatcher.task.TaskPriority;
import ohos.data.DatabaseHelper;
import ohos.data.preferences.Preferences;
import ohos.eventhandler.EventRunner;
import ohos.global.resource.RawFileDescriptor;
import ohos.media.player.Player;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* This is player implementation based on {@link ohos.agp.components.surfaceprovider.SurfaceProvider}
* It encapsulates {@link Player}.
* <p>
* It ensures that MediaPlayer methods are called from not main thread.
* MediaPlayer methods are directly connected with hardware. That's why they should not be called from UI thread
*
* @author danylo.ohos
*/
public class VideoPlayerView extends ScalableTextureView
implements
TextureView.SurfaceTextureListener,
MediaPlayerWrapper.MainThreadMediaPlayerListener,
MediaPlayerWrapper.VideoStateListener {
private static final boolean SHOW_LOGS = Config.SHOW_LOGS;
private String TAG = VideoPlayerView.class.getSimpleName();
private static final String IS_VIDEO_MUTED = "IS_VIDEO_MUTED";
// private HandlerThreadExtension mViewHandlerBackgroundThread;
/**
* A Listener that propagates {@link Player} listeners is background thread.
* Probably call of this listener should also need to be synchronized with it creation and destroy places.
*/
private BackgroundThreadMediaPlayerListener mMediaPlayerListenerBackgroundThread;
private MediaPlayerWrapper.VideoStateListener mVideoStateListener;
// private SurfaceTextureListener mLocalSurfaceTextureListener;
private RawFileDescriptor mAssetFileDescriptor;
private String mPath;
private Context mContext;
private final ReadyForPlaybackIndicator mReadyForPlaybackIndicator = new ReadyForPlaybackIndicator();
private final Set<MediaPlayerWrapper.MainThreadMediaPlayerListener> mMediaPlayerMainThreadListeners = new HashSet<>();
private SurfaceOps surfaceOps;
public MediaPlayerWrapper.State getCurrentState() {
synchronized (mReadyForPlaybackIndicator) {
return mMediaPlayer.getCurrentState();
}
}
public RawFileDescriptor getAssetFileDescriptorDataSource() {
return mAssetFileDescriptor;
}
public String getVideoUrlDataSource() {
return mPath;
}
public interface BackgroundThreadMediaPlayerListener {
void onVideoSizeChangedBackgroundThread(int width, int height);
void onVideoPreparedBackgroundThread();
void onVideoCompletionBackgroundThread();
void onErrorBackgroundThread(int what, int extra);
}
public VideoPlayerView(Context context) {
super(context);
mContext = context;
initView();
}
public VideoPlayerView(Context context, AttrSet attrs) {
super(context, attrs);
Logger.err(TAG + " context = " + context, "");
mContext = context;
initView();
}
/* public VideoPlayerView(Context context, Attr attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView();
}*/
/*
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public VideoPlayerView(Context context, AttrSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
initView();
}
*/
private void checkThread() {
if (EventRunner.current() == EventRunner.getMainEventRunner()) {
throw new RuntimeException("cannot be in main thread");
}
}
public void reset() {
checkThread();
synchronized (mReadyForPlaybackIndicator) {
mMediaPlayer.reset();
}
}
public void release() {
checkThread();
synchronized (mReadyForPlaybackIndicator) {
mMediaPlayer.release();
}
}
public void clearPlayerInstance() {
if (SHOW_LOGS) Logger.v(TAG, ">> clearPlayerInstance");
checkThread();
synchronized (mReadyForPlaybackIndicator) {
mReadyForPlaybackIndicator.setVideoSize(null, null);
mMediaPlayer.clearAll();
mMediaPlayer = null;
}
if (SHOW_LOGS) Logger.v(TAG, "<< clearPlayerInstance");
}
public void createNewPlayerInstance() {
if (SHOW_LOGS) Logger.v(TAG, ">> createNewPlayerInstance");
if (SHOW_LOGS) Logger.v(TAG, "createNewPlayerInstance main Looper " + EventRunner.getMainEventRunner());
if (SHOW_LOGS) Logger.v(TAG, "createNewPlayerInstance my Looper " + EventRunner.current());
checkThread();
synchronized (mReadyForPlaybackIndicator) {
//创建Player
mMediaPlayer = new MediaPlayerWrapperImpl(getContext());
// 设置时评宽和高
mReadyForPlaybackIndicator.setVideoSize(null, null);
mReadyForPlaybackIndicator.setFailedToPrepareUiForPlayback(false);
Logger.v(TAG, "isSurfaceTextureAvailable =" + mReadyForPlaybackIndicator.isSurfaceTextureAvailable());
mMediaPlayer.setMainThreadMediaPlayerListener(this);
mMediaPlayer.setVideoStateListener(this);
}
if (SHOW_LOGS) Logger.v(TAG, "<< createNewPlayerInstance");
}
public void prepare() {
checkThread();
synchronized (mReadyForPlaybackIndicator) {
mMediaPlayer.prepare();
}
}
public void stop() {
checkThread();
synchronized (mReadyForPlaybackIndicator) {
mMediaPlayer.stop();
}
}
private void notifyOnVideoStopped() {
if (SHOW_LOGS) Logger.v(TAG, "notifyOnVideoStopped");
List<MediaPlayerWrapper.MainThreadMediaPlayerListener> listCopy;
synchronized (mMediaPlayerMainThreadListeners) {
listCopy = new ArrayList<>(mMediaPlayerMainThreadListeners);
}
for (MediaPlayerWrapper.MainThreadMediaPlayerListener listener : listCopy) {
listener.onVideoStoppedMainThread();
}
}
private boolean isVideoSizeAvailable() {
boolean isVideoSizeAvailable = getContentHeight() != null && getContentWidth() != null;
if (SHOW_LOGS) Logger.v(TAG, "isVideoSizeAvailable " + isVideoSizeAvailable);
return isVideoSizeAvailable;
}
public void start() {
if (SHOW_LOGS) Logger.v(TAG, ">> start");
synchronized (mReadyForPlaybackIndicator) {
if (mReadyForPlaybackIndicator.isReadyForPlayback()) {
mMediaPlayer.start();
} else {
if (SHOW_LOGS) Logger.v(TAG, "start, >> wait");
if (!mReadyForPlaybackIndicator.isFailedToPrepareUiForPlayback()) {
try {
mReadyForPlaybackIndicator.wait();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if (SHOW_LOGS) Logger.v(TAG, "start, << wait");
if (mReadyForPlaybackIndicator.isReadyForPlayback()) {
mMediaPlayer.start();
} else {
if (SHOW_LOGS)
Logger.w(TAG, "start, movie is not ready, Player become STARTED state, but it will actually don't play");
}
} else {
if (SHOW_LOGS) Logger.w(TAG, "start, movie is not ready. Video size will not become available");
}
}
}
if (SHOW_LOGS) Logger.v(TAG, "<< start");
}
private void initView() {
TAG = "" + this;
if (SHOW_LOGS) Logger.v(TAG, "initV
没有合适的资源?快使用搜索试试~ 我知道了~
harmonyos实现的VideoPlayerManager功能,一个旨在帮助控制player类的项目
共110个文件
java:67个
xml:11个
json:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 45 浏览量
2023-05-15
16:49:26
上传
评论
收藏 69.26MB ZIP 举报
温馨提示
harmonyos实现的VideoPlayerManager功能,这是一个旨在帮助控制player类的项目。在Listcontainer中使用播放器更容易。video_player_manager包提供了在后台线程中调用Player播放器方法的功能。 当列表中有多个媒体文件时,它有一个只能播放一次的实用程序。在开始新的播放之前,它将停止旧的播放并释放所有资源。List_visibility_utils包,这是一个库,用于跟踪列表中最可见的项并在它们更改时通知。
资源推荐
资源详情
资源评论
收起资源包目录
harmonyos实现的VideoPlayerManager功能,一个旨在帮助控制player类的项目 (110个子文件)
gradlew.bat 3KB
.gitignore 237B
.gitignore 7B
.gitignore 7B
.gitignore 7B
build.gradle 848B
build.gradle 747B
build.gradle 435B
build.gradle 433B
settings.gradle 68B
gradlew 6KB
gradle-wrapper.jar 57KB
VideoPlayerView.java 27KB
MediaPlayerWrapper.java 24KB
SingleListViewItemActiveCalculator.java 19KB
SingleVideoPlayerManager.java 18KB
ScalableTextureView.java 11KB
VideoListViewFraction.java 8KB
BaseVideoItem.java 6KB
MainAbilitySlice.java 5KB
VideoView.java 5KB
TextureView.java 5KB
VideoPlayerManagerFraction.java 5KB
VisibilityUtilsFraction.java 5KB
ListView.java 5KB
HandlerThread.java 5KB
MessagesHandlerThread.java 4KB
VisibilityItem.java 4KB
Start.java 4KB
ScrollDirectionDetector.java 3KB
RecyclerViewItemPositionGetter.java 3KB
AbsListView.java 3KB
BaseItemsVisibilityCalculator.java 3KB
HandlerThreadExtension.java 2KB
ListViewItemPositionGetter.java 2KB
ListItemData.java 2KB
RawVideoItem.java 2KB
ViewListContainerItem.java 2KB
Prepare.java 2KB
ReadyForPlaybackIndicator.java 2KB
PlayerMessage.java 2KB
VideoPlayerManager.java 2KB
PlayerQueueLock.java 2KB
LogUtils.java 2KB
DefaultSingleItemCalculatorCallback.java 2KB
VisibilityUtilsAdapter.java 1KB
SetNewViewForPlayback.java 1KB
ListItem.java 1KB
Logger.java 1KB
VideoViewHolder.java 1KB
Logger.java 1KB
MainAbility.java 1KB
ApplicationContext.java 1012B
SetAssetsDataSourceMessage.java 984B
CreateNewPlayerInstance.java 977B
ClearPlayerInstance.java 956B
Release.java 928B
LogUtils.java 922B
Reset.java 916B
Stop.java 901B
SetUrlDataSourceMessage.java 829B
SetDataSourceMessage.java 777B
SimpleMainThreadMediaPlayerListener.java 729B
CurrentItemMetaData.java 671B
VideoPlayerManagerCallback.java 670B
ItemsPositionGetter.java 597B
ItemFactory.java 596B
ListItemsVisibilityCalculator.java 565B
VideoItem.java 563B
PlayerMessageState.java 499B
Holder.java 345B
MediaPlayerWrapperImpl.java 309B
PlayerItemChangeListener.java 260B
Message.java 213B
MyApplication.java 209B
Config.java 174B
ExampleTest.java 126B
Config.java 116B
MetaData.java 78B
config.json 1KB
config.json 510B
config.json 508B
string.json 199B
string.json 99B
string.json 98B
LICENSE 653B
video_sample_3.mp4 16.92MB
video_sample_2.mp4 16.07MB
video_sample_1.mp4 15.93MB
video_sample_4.mp4 14.81MB
video_sample_4_pic.png 2.65MB
video_sample_1_pic.png 1.94MB
video_sample_3_pic.png 1.36MB
video_sample_2_pic.png 1007KB
icon.png 7KB
menu.png 2KB
local.properties 561B
gradle.properties 549B
gradle-wrapper.properties 194B
commondialog.xml 2KB
共 110 条
- 1
- 2
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6822
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功