不能向搜索者添加搜索栏
我指的是
https://medium.com/google-exoplayer/customizing-exoplayers-ui-components-728cf55ee07a
添加自定义播放暂停按钮和搜索栏到exoplayer
这是我正在尝试的代码
public class ExoplayerAct extends Activity implements VIDeoRendererEventListener { private static final String TAG = "MainActivity"; private SimpleExoPlayerVIEw simpleExoPlayerVIEw; private SimpleExoPlayer player; private TextVIEw resolutionTextVIEw; String j; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.exoplayer); resolutionTextVIEw = new TextVIEw(this); resolutionTextVIEw = (TextVIEw) findVIEwByID(R.ID.resolution_textVIEw); Intent iin = getIntent(); Bundle b = iin.getExtras(); if (b != null) { j = (String) b.get("fileVIDeoPath"); }// 1. Create a default TrackSelector BanDWIDthMeter banDWIDthMeter = new DefaultBanDWIDthMeter(); TrackSelection.Factory vIDeoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(banDWIDthMeter); TrackSelector trackSelector = new DefaultTrackSelector(vIDeoTrackSelectionFactory);// 2. Create a default LoadControl LoadControl loadControl = new DefaultLoadControl();// 3. Create the player player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl); simpleExoPlayerVIEw = new SimpleExoPlayerVIEw(this); simpleExoPlayerVIEw = (SimpleExoPlayerVIEw) findVIEwByID(R.ID.player_vIEw);//Set media controller simpleExoPlayerVIEw.setUseController(true); simpleExoPlayerVIEw.requestFocus();// Bind the player to the vIEw. simpleExoPlayerVIEw.setPlayer(player);// I. ADJUST HERE://CHOOSE CONTENT: liveStream / SdCard//liVE STREAM SOURCE: * livestream links may be out of date so find any m3u8 files online and replace:// Uri mp4VIDeoUri =Uri.parse("http://81.7.13.162/hls/ss1/index.m3u8"); //random 720p source// Uri mp4VIDeoUri =Uri.parse("http://54.255.155.24:1935//live/_definst_/amlst:sweetbcha1novD235L240P/playList.m3u8"); //Radnom 540p indian channel// Uri mp4VIDeoUri =Uri.parse("FIND A WORKING link ABD PLUg INTO HERE"); //PLUG INTO HERE<------------------------------------------//VIDEO FROM SD CARD: (2 steps. set up file and path, then change vIDeoSource to get the file)// String urimp4 = "path/filename.mp4"; //upload file to device and add path/name.mp4// Uri mp4VIDeoUri = Uri.parse(Environment.getExternalStorageDirectory().getabsolutePath()+"/2010a.mp4"); Uri mp4VIDeoUri = Uri.parse(j);//Measures banDWIDth during playback. Can be null if not required. DefaultBanDWIDthMeter banDWIDthMetera = new DefaultBanDWIDthMeter();//Produces DataSource instances through which media data is loaded. DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this , Util.getUserAgent(this, "exoplayer2example"), banDWIDthMetera);//Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();// II. ADJUST HERE://This is the MediaSource representing the media to be played://FOR SD CARD SOURCE: MediaSource vIDeoSource = new ExtractorMediaSource(mp4VIDeoUri, dataSourceFactory, extractorsFactory, null, null);//FOR liVESTREAM link:// MediaSource vIDeoSource = new HlsMediaSource(mp4VIDeoUri, dataSourceFactory, 1, null, null); final LooPingMediaSource looPingSource = new LooPingMediaSource(vIDeoSource);// Prepare the player with the source. player.prepare(looPingSource); player.addListener(new ExoPlayer.EventListener() { @OverrIDe public voID onTimelineChanged(Timeline timeline, Object manifest) { Log.v(TAG, "Listener-onTimelineChanged..."); } @OverrIDe public voID onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { Log.v(TAG, "Listener-onTracksChanged..."); } @OverrIDe public voID onl oadingChanged(boolean isLoading) { Log.v(TAG, "Listener-onLoadingChanged...isLoading:"+isLoading); } @OverrIDe public voID onPlayerStateChanged(boolean playWhenReady, int playbackState) { Log.v(TAG, "Listener-onPlayerStateChanged..." + playbackState); } @OverrIDe public voID onRepeatModeChanged(int repeatMode) { Log.v(TAG, "Listener-onRepeatModeChanged..."); } @OverrIDe public voID onPlayerError(ExoPlaybackException error) { Log.v(TAG, "Listener-onPlayerError..."); player.stop(); player.prepare(looPingSource); player.setPlayWhenReady(true); } @OverrIDe public voID onpositiondiscontinuity() { Log.v(TAG, "Listener-onpositiondiscontinuity..."); } @OverrIDe public voID onPlaybackParametersChanged(PlaybackParameters playbackParameters) { Log.v(TAG, "Listener-onPlaybackParametersChanged..."); } }); PlaybackParameters playbackParameters = new PlaybackParameters(2.0f, 1.0f); player.setPlaybackParameters(playbackParameters); player.setPlayWhenReady(true); //run file/link when ready to play. player.setVIDeoDeBUGListener(this); //for Listening to resolution change and outputing the resolution }//End of onCreate @OverrIDe public voID onVIDeoEnabled(DecoderCounters counters) { } @OverrIDe public voID onVIDeoDecoderInitialized(String decodername, long initializedTimestampMs, long initializationDurationMs) { } @OverrIDe public voID onVIDeoinputFormatChanged(Format format) { } @OverrIDe public voID onDroppedFrames(int count, long elapsedMs) { } @OverrIDe public voID onVIDeoSizeChanged(int wIDth, int height, int unapplIEdRotationdegrees, float pixelWIDthHeightRatio) { Log.v(TAG, "onVIDeoSizeChanged [" + " wIDth: " + wIDth + " height: " + height + "]"); resolutionTextVIEw.setText("RES:(WxH):"+wIDth+"X"+height +"\n "+height+"p"); } @OverrIDe public voID onRenderedFirstFrame(Surface surface) { } @OverrIDe public voID onVIDeoDisabled(DecoderCounters counters) { }//-------------------------------------------------------ANDROID liFECYCLE--------------------------------------------------------------------------------------------- @OverrIDe protected voID onStop() { super.onStop(); Log.v(TAG, "onStop()..."); } @OverrIDe protected voID onStart() { super.onStart(); Log.v(TAG, "onStart()..."); } @OverrIDe protected voID onResume() { super.onResume(); Log.v(TAG, "onResume()..."); } @OverrIDe protected voID onPause() { super.onPause(); Log.v(TAG, "onPause()..."); } @OverrIDe protected voID onDestroy() { super.onDestroy(); Log.v(TAG, "onDestroy()..."); player.release(); }}
exoplayer布局是
<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:tools="http://schemas.androID.com/tools" xmlns:app="http://schemas.androID.com/apk/res-auto" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:paddingBottom="@dimen/fab_margin" androID:paddingleft="@dimen/fab_margin" androID:paddingRight="@dimen/fab_margin" androID:paddingtop="@dimen/fab_margin" tools:context="com.ayalus.exoplayer2example.MainActivity"> <TextVIEw androID:ID="@+ID/sample_app_Title" androID:text="ExoPlayer 2 Example App:" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:textSize="40sp" androID:textcolor="#000000" androID:gravity="center_horizontal"/> <TextVIEw androID:ID="@+ID/resolution_textVIEw" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:text="Resolution" androID:textSize="40px" androID:background="#FFFFFF" androID:textcolor="#000000" androID:layout_below="@+ID/sample_app_Title" androID:gravity="center_horizontal"/> <com.Google.androID.exoplayer2.ui.SimpleExoPlayerVIEw androID:ID="@+ID/player_vIEw" androID:focusable="true" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:layout_below="@+ID/resolution_textVIEw" app:use_controller="false" androID:layout_margintop="10dp" /></relativeLayout>
和自定义exo_playback_control_vIEw
是
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_gravity="bottom" androID:layoutDirection="ltr" androID:background="#CC000000" androID:orIEntation="vertical"> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:gravity="center" androID:paddingtop="4dp" androID:orIEntation="horizontal"> <Imagebutton androID:ID="@ID/exo_prev" androID:visibility="gone" /> <Imagebutton androID:ID="@ID/exo_rew" androID:visibility="gone" /> <Imagebutton androID:ID="@ID/exo_play" /> <Imagebutton androID:ID="@ID/exo_pause" /> <Imagebutton androID:ID="@ID/exo_ffwd" androID:visibility="gone" /> <Imagebutton androID:ID="@ID/exo_next" androID:visibility="gone" /> </linearLayout> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_margintop="4dp" androID:gravity="center_vertical" androID:orIEntation="horizontal"> <TextVIEw androID:ID="@ID/exo_position" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:textSize="14sp" androID:textStyle="bold" androID:paddingleft="4dp" androID:paddingRight="4dp" androID:includeFontpadding="false" androID:textcolor="#FFBEBEBE"/> <!--<Seekbar androID:ID="@ID/exo_progress"--> <!--androID:layout_wIDth="0dp"--> <!--androID:layout_weight="1"--> <!--androID:layout_height="32dp"--> <!--androID:focusable="false"--> <!--/>--> <TextVIEw androID:ID="@ID/exo_duration" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:textSize="14sp" androID:textStyle="bold" androID:paddingleft="4dp" androID:paddingRight="4dp" androID:includeFontpadding="false" androID:textcolor="#FFBEBEBE"/> </linearLayout></linearLayout>
如果我如上所述评论搜索栏,它可以正常工作
但如果我添加了搜索栏,它会给我错误
Caused by: java.lang.classCastException: androID.Widget.Seekbar cannot be cast to com.Google.androID.exoplayer2.ui.Timebar
解决方法:
在exo_playback_control_vIEw布局中,用com.Google.androID.exoplayer2.ui.DefaultTimebar替换Seekbar
这是错误消息告诉您的内容,如果您检查文档here,您会发现为exo_progress控件指定的类型确实是Timebar.
<com.Google.androID.exoplayer2.ui.DefaultTimebar androID:ID="@ID/exo_progress" androID:layout_wIDth="0dp" androID:layout_weight="1" androID:layout_height="26dp"/>
总结 以上是内存溢出为你收集整理的android – 如何将搜索栏添加到Exoplayer exo_playback_control_view.xml全部内容,希望文章能够帮你解决android – 如何将搜索栏添加到Exoplayer exo_playback_control_view.xml所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)