Android Studio VideoFragment无法解析符号VideoFragment_

时间:2019-10-20 21:06:43

标签: java android-studio android-fragments

我正在尝试在Android Studio 3.5.1中使用带有exo播放器的Danikula AndroidVideoCache实现视频片段,但是出现错误

  

无法解析符号VideoFragment_ /错误:找不到符号变量VideoFragment _

我环顾四周并尝试了所有建议的解决方案,例如使缓存无效并重新启动,使用gradle同步项目,将项目迁移到androidx

这是VideoFragment类

import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.ImageView;
import android.widget.ProgressBar;
//import androidx.core.app.Fragment;
import androidx.fragment.app.Fragment;
import com.danikula.videocache.CacheListener;
import com.danikula.videocache.HttpProxyCacheServer;
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.LoadControl;
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;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.FragmentArg;
import org.androidannotations.annotations.SeekBarTouchStop;
import org.androidannotations.annotations.ViewById;
import java.io.File;

@EFragment(R.layout.fragment_video)
public class VideoFragment extends Fragment implements CacheListener {

private static final String LOG_TAG = "VideoFragment";

@FragmentArg String url;

@ViewById ImageView cacheStatusImageView;
@ViewById SimpleExoPlayerView simpleExoPlayerView;
@ViewById ProgressBar progressBar;
private SimpleExoPlayer simpleExoPlayer;

private final VideoProgressUpdater updater = new VideoProgressUpdater();

public static Fragment build(String url) {
  return VideoFragment_.builder()
           .url(url)
           .build();
}

@AfterViews
void afterViewInjected() {
    checkCachedState();

    simpleExoPlayer = setupPlayer();
    simpleExoPlayer.setPlayWhenReady(true);
}

private void checkCachedState() {
    HttpProxyCacheServer proxy = App.getProxy(getActivity());
    boolean fullyCached = proxy.isCached(url);
    setCachedState(fullyCached);
    if (fullyCached) {
        progressBar.setSecondaryProgress(100);
    }
}

private SimpleExoPlayer setupPlayer() {
    simpleExoPlayerView.setUseController(false);
    HttpProxyCacheServer proxy = App.getProxy(getActivity());
    proxy.registerCacheListener(this, url);
    String proxyUrl = proxy.getProxyUrl(url);
    Log.d(LOG_TAG, "Use proxy url " + proxyUrl + " instead of original url " + url);

    SimpleExoPlayer exoPlayer = newSimpleExoPlayer();
    simpleExoPlayerView.setPlayer(exoPlayer);

    MediaSource videoSource = newVideoSource(proxyUrl);
    exoPlayer.prepare(videoSource);

    return exoPlayer;
}

private SimpleExoPlayer newSimpleExoPlayer() {
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
    TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
    LoadControl loadControl = new DefaultLoadControl();
    return ExoPlayerFactory.newSimpleInstance(getActivity(), trackSelector, loadControl);
}

private MediaSource newVideoSource(String url) {
    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    String userAgent = Util.getUserAgent(getActivity(), "Usign App");
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getActivity(), userAgent, bandwidthMeter);
    ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
    return new ExtractorMediaSource(Uri.parse(url), dataSourceFactory, extractorsFactory, null, null);
}

@Override
public void onResume() {
    super.onResume();
    updater.start();
    simpleExoPlayer.setPlayWhenReady(true);
}

@Override
public void onPause() {
    super.onPause();
    updater.stop();
    simpleExoPlayer.setPlayWhenReady(false);
}

@Override
public void onDestroy() {
    super.onDestroy();

    simpleExoPlayer.release();
    App.getProxy(getActivity()).unregisterCacheListener(this);
}

@Override
public void onCacheAvailable(File file, String url, int percentsAvailable) {
    progressBar.setSecondaryProgress(percentsAvailable);
    setCachedState(percentsAvailable == 100);
    Log.d(LOG_TAG, String.format("onCacheAvailable. percents: %d, file: %s, url: %s", percentsAvailable, file, url));
}

private void updateVideoProgress() {
    long videoProgress = simpleExoPlayer.getCurrentPosition() * 100 / simpleExoPlayer.getDuration();
    progressBar.setProgress((int) videoProgress);
}

@SeekBarTouchStop(R.id.progressBar)
void seekVideo() {
    long videoPosition = simpleExoPlayer.getDuration() * progressBar.getProgress() / 100;
    simpleExoPlayer.seekTo(videoPosition);
}

private void setCachedState(boolean cached) {
    int statusIconId = cached ? R.drawable.ic_cloud_done : R.drawable.ic_cloud_download;
    cacheStatusImageView.setImageResource(statusIconId);
}

private final class VideoProgressUpdater extends Handler {

    public void start() {
        sendEmptyMessage(0);
    }

    public void stop() {
        removeMessages(0);
    }

    @Override
    public void handleMessage(Message msg) {
        updateVideoProgress();
        sendEmptyMessageDelayed(0, 500);
    }
}

}

我的build.gradle

buildscript {
repositories {
    mavenCentral()
}
dependencies {

    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}

apply plugin: 'com.android.application'

android {
signingConfigs {
    config {
        keyAlias 'usigfdfnkey'
        keyPassword 'usigdsc0n222'
        storeFile file('C:/APPKEYS/key/usdskkldgn.jks')
        storePassword 'usign54s222'
    }
}
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
    applicationId "com.javms.usetgn"
    minSdkVersion 16
    targetSdkVersion 28
    versionCode 1
    versionName "1"
    multiDexEnabled true
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    signingConfig signingConfigs.config
  }
  buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.config
    }
    debug {
        signingConfig signingConfigs.config
    }
  }
  productFlavors {
  }

  compileOptions {
    targetCompatibility JavaVersion.VERSION_1_8
   }
   }

   allprojects {

    repositories {
    mavenLocal()
    google()
    jcenter()
    mavenCentral()

    maven { url 'https://github.com/dahlgren/vpi-aar/raw/master' }

    }

    }

   dependencies {
   implementation fileTree(include: ['*.jar'], dir: 'libs')
   implementation 'com.morsebyte.shailesh.twostagerating:TwoStageRate:2.0'
   implementation 'com.thefinestartist:finestwebview:1.2.7'
   implementation 'com.google.firebase:firebase-core:16.0.1'
   implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
   implementation 'androidx.appcompat:appcompat:1.1.0'
   implementation 'com.cuneytayyildiz:onboarder:1.0.4'
   implementation 'androidx.multidex:multidex:2.0.1'
   implementation 'com.google.android.material:material:1.0.0'
   implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
   implementation 'androidx.legacy:legacy-support-v4:1.0.0'
   implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
   implementation 'de.hdodenhof:circleimageview:3.0.1'
   implementation 'androidx.recyclerview:recyclerview:1.0.0'
   implementation 'com.google.firebase:firebase-auth:11.6.0'
   implementation 'com.google.firebase:firebase-ads:15.0.1'
   implementation 'com.facebook.android:facebook-android-sdk:5.8.0'
   testImplementation 'junit:junit:4.12'
   androidTestImplementation 'androidx.test:runner:1.1.0'
   androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
   implementation 'com.google.android.material:material:1.0.0'
   implementation 'androidx.gridlayout:gridlayout:1.0.0'
   //Exoplayer
   implementation 'com.google.android.exoplayer:exoplayer:2.10.2'
   implementation 'com.google.android.exoplayer:exoplayer-core:2.10.2'
   implementation 'com.google.android.exoplayer:exoplayer-dash:2.10.2'
   implementation 'com.google.android.exoplayer:exoplayer-ui:2.10.2'
   //Exo
   implementation 'com.danikula:videocache:2.7.1'
   implementation 'org.androidannotations:androidannotations-api:4.6.0'
   implementation 'com.viewpagerindicator:library:2.4.2-SNAPSHOT@aar'
   implementation 'androidx.legacy:legacy-support-v4:1.0.0'
   implementation 'androidx.appcompat:appcompat:1.0.0'
   implementation 'pub.devrel:easypermissions:0.3.0'
   implementation 'io.square1:richtext:6.0.25'
   implementation 'com.github.medyo:android-about-page:1.2.5'
   implementation 'io.github.angebagui.mediumtextview:mediumtextview:1.0.1'
   implementation('com.google.api-client:google-api-client-android:1.23.0') {
    exclude group: 'org.apache.httpcomponents'
   }
   }
   apply plugin: 'com.google.gms.google-services'

0 个答案:

没有答案