android 播放动画前黑屏,android videoview 播放前黑屏的解決方法之一

Android VideoView在加载资源时可能会出现短暂的黑屏现象。为避免这种情况,可以在布局中设置一个遮罩,并在VideoView的准备就绪监听回调中移除遮罩。这种方法确保了在资源加载完成前有一个过渡效果。通过监听`OnPreparedListener`并在回调中设置遮罩的可见性为`GONE`,可以实现流畅的播放体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://stackoverflow.com/questions/9765629/android-videoview-black-screen

播放前黑屏的原因是videoview加載資源需要一定的耗時, 如何避免播放前的黑屏現象呢, 可以給videoview設置加載的監聽, 如果加載前給一個遮罩,等資源加載完成后隱藏遮罩.

如果有更好的解決方法,歡迎留言

899229cfab2c02d614490485cabb781b.jpe

采用這樣解決方案: 需要videoview放到framelayout布局中:

android:id="@+id/frameLayout1"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_gravity="center"

android:layout_marginTop="50dip" >

android:id="@+id/geoloc_anim"

android:layout_width="fill_parent"

android:layout_height="172dip" android:layout_gravity="top|center" android:visibility="visible"/>

android:id="@+id/placeholder"

android:layout_width="fill_parent"

android:layout_height="fill_parent" android:background="@drawable/fondvert_anim">

videoview設置監聽:

videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

@Override

public void onPrepared(MediaPlayer mediaPlayer) {

//Called when the video is ready to play

View placeholder = findViewById(R.id.placeholder);

placeholder.setVisibility(View.GONE);

}

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值