Java 自定义Exoplayer播放和暂停按钮
我是android的初学者。我想更改ExoPlayer视图界面中心的播放和暂停按钮的位置,就像Facebook一样。在这里,我使用Exoplayer和三个文本视图创建了一个MainActivity,用于滚动 我插入了一个名为 编译com.google.android.exoplayer:exoplayer:r2.4.4到build.gradle模块应用程序。然后我把它用在我的活动中。以下是我的代码,我也非常感谢您的解决方案 activity_main.xml代码Java 自定义Exoplayer播放和暂停按钮,java,android,android-layout,android-mediaplayer,Java,Android,Android Layout,Android Mediaplayer,我是android的初学者。我想更改ExoPlayer视图界面中心的播放和暂停按钮的位置,就像Facebook一样。在这里,我使用Exoplayer和三个文本视图创建了一个MainActivity,用于滚动 我插入了一个名为 编译com.google.android.exoplayer:exoplayer:r2.4.4到build.gradle模块应用程序。然后我把它用在我的活动中。以下是我的代码,我也非常感谢您的解决方案 activity_main.xml代码 ?xml version="1.
?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:layout_width="match_parent"
android:layout_height="350dp"
android:id="@+id/simple_expo_player">
</com.google.android.exoplayer2.ui.SimpleExoPlayerView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello world"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello world"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello world"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
检查这个
package com.example.theace.videoplayer;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.ui.SimpleExoPlayerView;
import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
public class MainActivity extends AppCompatActivity {
private SimpleExoPlayerView simpleExoPlayerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initUi();
}
public void initUi(){
// 1. Create a default TrackSelector
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
// 2. Create the player
SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector);
// 3. Produces DataSource instances through which media data is loaded.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(), Util.getUserAgent(getApplicationContext(), "com.example.theace.videoplayer"));
// 4. Produces Extractor instances for parsing the media data.
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
// 5. This is the MediaSource representing the media to be played.
MediaSource videoSource = new ExtractorMediaSource(Uri.parse("https://www.w3schools.com/html/mov_bbb.mp4"),dataSourceFactory, extractorsFactory, null, null);
// 6. Prepare the player with the source.
player.prepare(videoSource);
simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.simple_expo_player);
simpleExoPlayerView.setPlayer(player);
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:layout_width="match_parent"
android:layout_height="350dp"
android:id="@+id/simple_expo_player">
</com.google.android.exoplayer2.ui.SimpleExoPlayerView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Play"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Pause"/>
</LinearLayout>
</RelativeLayout>