视频在res的raw文件中,如何获取
时间: 2024-02-25 22:51:47 浏览: 26
如果你想在代码中使用res/raw文件夹中的视频,你可以使用以下代码获取视频资源ID:
```java
int rawId = getResources().getIdentifier("your_video_file_name", "raw", getPackageName());
```
其中,`your_video_file_name` 是你的视频文件名(不包含扩展名),`raw` 是资源类型,`getPackageName()` 是你的应用程序包名。
获取到资源ID后,你可以将其传递给MediaPlayer或GSYVideoPlayer进行播放。例如:
```java
// 创建MediaPlayer
MediaPlayer mediaPlayer = MediaPlayer.create(this, rawId);
// 将MediaPlayer传递给GSYVideoPlayer进行播放
GSYVideoPlayer videoPlayer = findViewById(R.id.video_player);
videoPlayer.setUp(mediaPlayer, false, "");
videoPlayer.startPlayLogic();
```
注意,你需要在布局文件中先定义GSYVideoPlayer:
```xml
<com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
android:id="@+id/video_player"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
```
其中,`R.id.video_player` 是GSYVideoPlayer的ID,你需要根据实际情况进行调整。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)