gpt4 book ai didi

java - 我想要在 oncreate() Activity 之外从另一个类中提取 exoplayer 中的 YouTube 链接

转载 作者:行者123 更新时间:2023-12-02 03:06:15 25 4
gpt4 key购买 nike

从我的recyclerview适配器类通过intent put extra我正在传递视频的URL,并且我想在onc​​reate() Activity 之外获取intent。以在oncreate()之外的另一个字符串中传递URL。是否有可能在 oncreate 之外访问 getintent 字符串?

在这个类中,我想在 ONCREATE() 之前获取视频 URL 的 Intent ,以传递 URL 而不是静态 URL;

package com.example.movies.uis;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.movies.R;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.ui.SimpleExoPlayerView;

import at.huber.youtubeExtractor.Format;
import at.huber.youtubeExtractor.VideoMeta;
import at.huber.youtubeExtractor.YouTubeExtractor;
import at.huber.youtubeExtractor.YtFile;

public class PlayerActivity extends AppCompatActivity {
SimpleExoPlayerView simpleExoPlayerView;
private String GRID_YOUTUBE_ID = "s9-Id1WJQyo";
private String BASE_URL = "https://www.youtube.com";
private String youtubeLink = BASE_URL + "/watch?v=" + GRID_YOUTUBE_ID;
//hello


@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player);
extractYoutubeUrl();
simpleExoPlayerView = findViewById(R.id.player);


String title = getIntent().getExtras().getString("title");
String urlYoutube = getIntent().getExtras().getString("videourl");


TextView tv_name = findViewById(R.id.txt_title);
tv_name.setText(title);





}


@SuppressLint("StaticFieldLeak")
private void extractYoutubeUrl() {
new YouTubeExtractor(this) {
@Override
public void onExtractionComplete(SparseArray<YtFile> sparseArray, VideoMeta vMeta) {
//Log.d("======>>>>>>>>>>>>>>>>>", "onExtractionComplete: "+ytFiles.toString());
if (sparseArray != null) {
for(int i=0, size = sparseArray.size(); i < size; i++){
YtFile ytFile = sparseArray.valueAt(i);
Format frmt = ytFile.getFormat();
if(frmt.getExt() == "mp4" || frmt.getExt() == "webm"){
// Log.d(">>>>>>>>>>>>>>>>>>>>>>", "index: " + i+ " path: "+ytFile);
}


playVideo(ytFile.getUrl());


}

}

}
}.extract(youtubeLink, true, true);
}

public void playVideo(String downloadUrl) {

simpleExoPlayerView.setPlayer(ExoPlayerCustomise.getSharedInstance(PlayerActivity.this).getSimpleExoPlayerView().getPlayer());

ExoPlayerCustomise.getSharedInstance(PlayerActivity.this).playStream(downloadUrl);
}






}

这是我的适配器类代码,它将 URL 传递给 Activity 单击项目

         public void onBindViewHolder(RecyclerviewAdpaterFragment70s.RecyclerViewHolder holder, int position) {

Context context = holder.cardthumnail.getContext();
Songsapis songs = songsapis.get(position);
holder.cardtitle.setText(songs.getTitle());
Picasso.with(context)
.load(songs.getThumbnail())
.into(holder.cardthumnail);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Context context = holder.itemView.getContext();
Intent i = new Intent(context, PlayerActivity.class);
i.putExtra("title",songsapis.get(position).getTitle());
i.putExtra("videourl",songsapis.get(position).getUrl());
context.startActivity(i);




}
});

}

最佳答案

您可以使用具有特定结构的深度链接

附加自爆线 list

定义 ACTION_VIEW Intent 操作,以便可以从 Google 搜索访问 Intent 过滤器

<action android:name="android.intent.action.VIEW" />

并添加可浏览类别,以便可以从外部应用程序访问

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

添加链接结构

<data android:host="youtube" android:pathPattern=".*" android:scheme="https"/>

有目的地获取数据

Intent intent = getIntent();
Uri data = intent.getData();

向应用程序发送数据

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://youtube"));
startActivity(launchIntent);

关于java - 我想要在 oncreate() Activity 之外从另一个类中提取 exoplayer 中的 YouTube 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57022085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com