大多数玩家需要一个支持部分内容请求(或字节范围)的控制器。
这可能有点难以实现,所以我建议使用类似Spring社区项目的东西
Spring Content
那么您根本不需要担心如何实现控制器。概念和编程模型与Spring数据非常相似,从外观上看,您已经在使用Spring数据了。
假设您使用的是Spring Boot(如果您不使用,请告诉我),则其外观如下:
pom.xml
<!-- Java API -->
<dependency>
<groupId>com.github.paulcwarren</groupId>
<artifactId>content-fs-spring-boot-starter</artifactId>
<version>0.6.0</version>
</dependency>
<!-- REST API -->
<dependency>
<groupId>com.github.paulcwarren</groupId>
<artifactId>spring-content-rest-boot-starter</artifactId>
<version>0.6.0</version>
</dependency>
SpringBootApplication.java
@SpringBootApplication
public class YourSpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(YourSpringBootApplication.class, args);
}
@Configuration
@EnableFilesystemStores
public static class StorageConfig {
File filesystemRoot() {
return new File("/path/to/your/sounds");
}
@Bean
public FileSystemResourceLoader fsResourceLoader() throws Exception {
return new FileSystemResourceLoader(filesystemRoot().getAbsolutePath());
}
}
@StoreRestResource(path="characterSounds")
public interface SoundsContentStore extends ContentStore<UUUID,String> {
//
}
}
java
public class Character {
@Id
@GeneratedValue
private Long id;
...other existing fields...
@ContentId
private UUID contentId;
@ContentLength
private Long contnetLength;
@MimeType
private String mimeType;
}
这就是您创建基于REST的音频服务所需的全部内容
/characterSounds
支持流媒体。它实际上也支持完整的CRUD功能;Create==POST,Read==GET(包括您需要的字节范围支持),Update==PUT,Delete==Delete(如果对您有用)。上传的声音将存储在“/path/to/your/sounds”中。
所以
GET /characterSounds/{characterId}
嗯