通过 Intent 传递对原始视频文件的引用并在另一个活动中使用它
在我当前的工作代码中,我从显示一些缩略图的屏幕传递图像的引用。当选择缩略图时,图像 ID 会被存储,然后在新的 Activity 中使用。现在,当选择缩略图时,我想存储图像 ID 和对关联视频文件的引用。
选择缩略图后,它会打开一个新活动,其中显示带有播放按钮的完整图像。选择播放按钮后,我希望它调用一个新活动,该活动将根据缩略图屏幕上保存的参考播放视频。除了使用参考播放视频之外,我一切正常。当我硬编码文件名时,视频就会播放。
这是我的代码的一些片段。
来自缩略图类:
public void onClick(View v) {
Intent fullImage = new Intent(standard_main.this, full_image.class);
Intent playVideo = new Intent(standard_main.this, video.class);
switch(v.getId()){
case R.id.img_standard1:
fullImage.putExtra("Full", R.drawable.img_standard1);
playVideo.putExtra("VideoFile", R.raw.standard); // added to try to reference video for future use
startActivity(fullImage);
break;
来自 full_image 类:
if (x >= leftPlayPoint && x < rightPlayPoint && y >= topPlayPoint && y < bottomPlayPoint){
startActivity(new Intent("com.example.PLAYVIDEO"));
来自我的视频类:
VideoView vd = (VideoView) findViewById(R.id.VideoView);
int vidID = getIntent().getIntExtra("VideoFile",0);
Uri uri = Uri.parse("android.resource://com.example/"+ R.raw.standard);
我想以某种方式使用 vidID 来替换 R.raw.standard。
如果我理解正确,我不能使用 vidID,因为它是一个 Int 而 Uri.parse 需要一个字符串。我尝试使用 toString() 将 Int 转换为 String,但我怀疑只将实际数字转换为字符串,并且确实引入了实际文件名。我也尝试过 String.valueOf(vidID)。
我认为 Parcelabel 可能会在某个地方使用,但我没有遵循如何使用它。我认为的另一种选择是将所有视频名称存储在一个数组中,并以某种方式使用它在 video.java 文件上动态创建文件名。
我会继续寻找,但非常感谢任何帮助。
In my current working code, I pass the reference of an image from a screen that shows some thumbnails. When the thumbnail is selected, the image id is stored and then used in a new activity. Now, when a thumbnail is selected, I want to store the image id and a reference to the associated video file.
When the thumbnail is selected, it opens a new activity that shows the full image with a play button. When the play button is selected, I want it to call a new activity that will play the video based on the reference saved on the thumbnail screen. I have everything working except getting the video to play using the reference. When I hard code the file name in, the video will play.
here's some snippets of my code.
From thumbnail class:
public void onClick(View v) {
Intent fullImage = new Intent(standard_main.this, full_image.class);
Intent playVideo = new Intent(standard_main.this, video.class);
switch(v.getId()){
case R.id.img_standard1:
fullImage.putExtra("Full", R.drawable.img_standard1);
playVideo.putExtra("VideoFile", R.raw.standard); // added to try to reference video for future use
startActivity(fullImage);
break;
From full_image class:
if (x >= leftPlayPoint && x < rightPlayPoint && y >= topPlayPoint && y < bottomPlayPoint){
startActivity(new Intent("com.example.PLAYVIDEO"));
From my video class:
VideoView vd = (VideoView) findViewById(R.id.VideoView);
int vidID = getIntent().getIntExtra("VideoFile",0);
Uri uri = Uri.parse("android.resource://com.example/"+ R.raw.standard);
I want to somehow use vidID to replace R.raw.standard.
If I'm understanding correctly, I cannot use vidID because it is an Int and Uri.parse wants a string. I tried converting the Int to a String using toString() but I suspect that only converted the actual number to a string and did bring in the actual file name. I also tried String.valueOf(vidID).
I'm thinking that Parcelabel might be used somewhere, but I'm not following how to use it. One other option I thought was to store all the video names in an array and somehow use this to dynamically create the file name on the video.java file.
I'll keep searching, but any help is much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种方法。也许有更简单的方法,但我不知道。
一些示例代码。
This is one way to do it. Perhaps there is an easier way, but none that I know of.
Some example code.