我正在构建一个基本上是 YouTube 克隆的应用程序。我使用官方的 video_player 插件进行播放,使用 Chewie 进行控制。我想实现一个质量切换器,以便用户可以决定他们希望视频以什么质量进行流式传输
我已经构建了一个带有开关的底部工作表,changeQuality()当用户选择所需的质量时我会运行。它应该做的只是向旧播放器提供新的源文件,并从视频离开的位置继续播放。
这是在 initState() 上运行的视频播放器和咀嚼播放器:
videoPlayer = VideoPlayerController.network(data == null
? dataAll[indexNo]["video"]["480"]
: data[indexNo]["video"]["480"]);
chewieController = ChewieController(
videoPlayerController: videoPlayer,
aspectRatio: 16 / 9,
autoPlay: true,
allowedScreenSleep: false,
placeholder: data == null
? Image(
image: NetworkImage(dataAll[indexNo]["thumbnail"]),
)
: Image(
image: NetworkImage(data[indexNo]["thumbnail"]),
)
);
Run Code Online (Sandbox Code Playgroud)
和changeQuality()功能:
changeQuality(String newQuality) {
setState(() {
position = videoPlayer.value.position;
chewieController.pause();
videoPlayer = new VideoPlayerController.network(data == null
? dataAll[indexNo]["video"]["$newQuality"]
: data[indexNo]["video"]["$newQuality"]);
chewieController = ChewieController(
videoPlayerController: videoPlayer,
aspectRatio: 16 / …Run Code Online (Sandbox Code Playgroud) 我已经使用 json 一段时间了,问题是我解码的字符串被编码为 Latin-1,我无法让它作为 UTF-8 工作。因此,某些字符显示不正确(例如'显示为')。
我已经在 stackoverflow 上阅读了一些问题,但它们似乎不起作用。
我正在使用的 json 结构如下所示(来自 YouTube API):
...
"items": [
{
...
"snippet": {
...
"title": "Powerbeats Pro “Totally Wireless” Except when you need a wire",
...
}
}
]
Run Code Online (Sandbox Code Playgroud)
我编码它:
...
"items": [
{
...
"snippet": {
...
"title": "Powerbeats Pro “Totally Wireless” Except when you need a wire",
...
}
}
]
Run Code Online (Sandbox Code Playgroud)
然后我尝试将第二行更改为:
response = await http.get(link, headers: {HttpHeaders.contentTypeHeader: "application/json; charset=utf-8"});
extractedData = json.decode(response.body);
dataTech = extractedData["items"];
Run Code Online (Sandbox Code Playgroud)
但这给了我关于错误格式的错误。所以我把它改成:
extractedData = json.decode(utf8.decode(response.body)); …Run Code Online (Sandbox Code Playgroud) 我不久前开始学习Java,我认为制作一个可以在终端中运行的计算器.最近我添加了一个数组列表来存储历史记录,然后出了点问题.计算器程序:
import java.util.Scanner;
import java.util.ArrayList;
public class calc_case {
public static void main(String[] args) {
System.out.println("Welcom to The Calculator!");
double a;
double b;
double c;
Scanner input0;
int input = 0;
ArrayList<Double> history = new ArrayList<Double>();
while (input != 6) {
try {Thread.sleep(2000);} catch(InterruptedException ex) {Thread.currentThread().interrupt();}
a = 0; b = 0; c = 0; input = 0;
System.out.println("#################################################");
System.out.println("How can I help you?");
System.out.println("1-Add\n2-Subtrackt\n3-Devide\n4-Multiply\n5-Show history\n6-Exit");
input0 = new Scanner(System.in);
input = input0.nextInt();
switch (input) {
case 1: //add
System.out.println("Input …Run Code Online (Sandbox Code Playgroud)