从我的recyclerview适配器类通过意图放入额外的内容,我正在传递视频的url,并且我想在oncreate()activity之外获取intent。将URL传递到oncreate()之外的另一个字符串中。是否有可能在oncreate之外访问getintent字符串?
in this class i want to getintent of video url before the ONCREATE() to
pass the url instead of static 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);
}
}
这是我的adpater类代码,它正在将url传递给活动
onclick项目
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);
}
});
}
最佳答案
您可以使用具有特定结构的深度链接
附加吹线清单
定义ACTION_VIEW意向操作,以便可以从Google搜索访问意向过滤器
<action android:name="android.intent.action.VIEW" />
并添加BROWSABLE类别,以便可以从外出应用访问
<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/