마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

exoPlayer 로컬 파일 재생이 안되네요.

0 추천

exoPlayer이용해서 동영상 재생 어플을 한번 만들어 보려고 하는데요.

구글링해서 어찌어찌 코딩은 했고,어플은 실행되는데 아무런 오류도 안나고, 파일 재생도 안되고, 아무런 동작을 안하네요

뭐가 잘못된걸까요?

테스트 기계가 갤럭시S8에 안드로이드9버전인데 이게 상관이 있을수도 있을까요?

 

아래 해당 소스입니다.

bundle.gradle 

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "app.example.exoplayer"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'

    // https://mvnrepository.com/artifact/com.google.android.exoplayer/exoplayer
    implementation 'com.google.android.exoplayer:exoplayer:2.8.4'
    implementation 'com.google.android.exoplayer:exoplayer-core:2.8.4'
    implementation 'com.google.android.exoplayer:exoplayer-ui:2.8.4'
 }

 

자바소스

private void initPlayer() {
    String url = Environment.getExternalStorageDirectory().getAbsolutePath() + "/English/test.avi";
    PlayerView playerView = findViewById(R.id.playerView);
    Log.e("exoPlayer", "url = " + url);
    File myFile = new File(url);
    String videoUrl= String.valueOf(Uri.fromFile(myFile));

    TrackSelection.Factory adaptiveTrackSelectionFactory =
            new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
    exoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector(), new DefaultLoadControl());
    playerView.setPlayer(exoPlayer);
    exoPlayer.addListener(new EventListener());
    exoPlayer.setPlayWhenReady(playWhenReady);
    exoPlayer.seekTo(currentWindow, playbackPosition);

    Uri uri = Uri.parse(videoUrl);
    MediaSource mediaSource = buildMediaSource(uri);
    Log.e("exoPlayer", "mediaSource = " + mediaSource);
    exoPlayer.prepare(mediaSource, true, false);
}

private MediaSource buildMediaSource(Uri uri) {
        return new ExtractorMediaSource.Factory(
                new DefaultDataSourceFactory(this,"Exoplayer")).
                createMediaSource(uri);
}

 

churry74 (120 포인트) 님이 2021년 11월 11일 질문
ExoPlayer를 사용해 보지 않아서 자세한 것 알려드릴 수 없고, 한두가지 체크해 보실 부분만 말씀드릴게요.
ExoPlayer의 Github 페이지를 보면:

If not enabled already, you also need to turn on Java 8 support in all build.gradle files depending on ExoPlayer, by adding the following to the android section:

compileOptions {
  targetCompatibility JavaVersion.VERSION_1_8
}

자바버전을 1.8맞추라고 되어 있네요.

External Storage를 사용하고 계신데, 이 부분은 최근에 새로운 OS 버전이 나올 때마다 변경사항이 있는 부분입니다. 따라서 버전에 따라 별도로 처리해야 하는 부분이 생길 수도 있으니, 개발자 문서를 살펴보시는게 좋아요.

그리고 구글 샘플 코드를 보면 API 23일 때와 아닐 때의 코드가 분기가 되고 있어요. 이 부분도 체크해 보세요.

그리고 Github페이지에 가시면 샘플 앱이 포함되어 있습니다. 이걸 분석해 보시면 많은 도움이 되리가 생각합니다.
https://github.com/google/ExoPlayer
https://github.com/google/ExoPlayer/tree/release-v2/demos
이제야..봤네요..답변 감사합니다

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...