Skip to content

Commit

Permalink
feat: ループ再生
Browse files Browse the repository at this point in the history
  • Loading branch information
kakkokari-gtyih committed Mar 7, 2024
1 parent 4ac797b commit 024a9f4
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 9 deletions.
4 changes: 4 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9765,6 +9765,10 @@ export interface Locale extends ILocale {
* 再生速度
*/
"playbackRate": string;
/**
* ループ再生
*/
"loop": string;
};
}
declare const locales: {
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2602,3 +2602,4 @@ _offlineScreen:
_mediaControls:
pip: "ピクチャインピクチャ"
playbackRate: "再生速度"
loop: "ループ再生"
11 changes: 11 additions & 0 deletions packages/frontend/src/components/MkMediaAudio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ function showMenu(ev: MouseEvent) {

menu = [
// TODO: 再生キューに追加
{
type: 'switch',
text: i18n.ts._mediaControls.loop,
icon: 'ti ti-repeat',
ref: loop,
},
{
type: 'radio',
text: i18n.ts._mediaControls.playbackRate,
Expand Down Expand Up @@ -217,6 +223,7 @@ const rangePercent = computed({
});
const volume = ref(.25);
const speed = ref(1);
const loop = ref(false); // TODO: ドライブファイルのフラグに置き換える
const bufferedEnd = ref(0);
const bufferedDataRatio = computed(() => {
if (!audioEl.value) return 0;
Expand Down Expand Up @@ -309,6 +316,10 @@ watch(speed, (to) => {
if (audioEl.value) audioEl.value.playbackRate = to;
});

watch(loop, (to) => {
if (audioEl.value) audioEl.value.loop = to;
});

onMounted(() => {
init();
});
Expand Down
11 changes: 11 additions & 0 deletions packages/frontend/src/components/MkMediaVideo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ function showMenu(ev: MouseEvent) {

menu = [
// TODO: 再生キューに追加
{
type: 'switch',
text: i18n.ts._mediaControls.loop,
icon: 'ti ti-repeat',
ref: loop,
},
{
type: 'radio',
text: i18n.ts._mediaControls.playbackRate,
Expand Down Expand Up @@ -269,6 +275,7 @@ const rangePercent = computed({
});
const volume = ref(.25);
const speed = ref(1);
const loop = ref(false); // TODO: ドライブファイルのフラグに置き換える
const bufferedEnd = ref(0);
const bufferedDataRatio = computed(() => {
if (!videoEl.value) return 0;
Expand Down Expand Up @@ -414,6 +421,10 @@ watch(speed, (to) => {
if (videoEl.value) videoEl.value.playbackRate = to;
});

watch(loop, (to) => {
if (videoEl.value) videoEl.value.loop = to;
});

watch(hide, (to) => {
if (to && isFullscreen.value) {
document.exitFullscreen();
Expand Down
8 changes: 5 additions & 3 deletions packages/frontend/src/components/MkMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ SPDX-License-Identifier: AGPL-3.0-only
</div>
</button>
<button v-else-if="item.type === 'switch'" role="menuitemcheckbox" :tabindex="i" class="_button" :class="[$style.item, $style.switch, { [$style.switchDisabled]: item.disabled } ]" @click="switchItem(item)" @mouseenter.passive="onItemMouseEnter(item)" @mouseleave.passive="onItemMouseLeave(item)">
<MkSwitchButton :class="$style.switchButton" :checked="item.ref" :disabled="item.disabled" @toggle="switchItem(item)"/>
<i v-if="item.icon" class="ti-fw" :class="[$style.icon, item.icon]"></i>
<MkSwitchButton v-else :class="$style.switchButton" :checked="item.ref" :disabled="item.disabled" @toggle="switchItem(item)"/>
<div :class="$style.item_content">
<span :class="[$style.item_content_text, $style.switchText]">{{ item.text }}</span>
<span :class="[$style.item_content_text, { [$style.switchText]: !item.icon }]">{{ item.text }}</span>
<MkSwitchButton v-if="item.icon" :class="[$style.switchButton, $style.caret]" :checked="item.ref" :disabled="item.disabled" @toggle="switchItem(item)"/>
</div>
</button>
<button v-else-if="item.type === 'radio'" class="_button" role="menuitem" :tabindex="i" :class="[$style.item, $style.parent, { [$style.childShowing]: childShowingItem === item }]" @mouseenter="preferClick ? null : showRadioOptions(item, $event)" @click="!preferClick ? null : showRadioOptions(item, $event)">
Expand Down Expand Up @@ -468,11 +470,11 @@ onBeforeUnmount(() => {

.switchButton {
margin-left: -2px;
--height: 1.35em;
}

.switchText {
margin-left: 8px;
margin-top: 2px;
overflow: hidden;
text-overflow: ellipsis;
}
Expand Down
13 changes: 8 additions & 5 deletions packages/frontend/src/components/MkSwitch.button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ const toggle = () => {

<style lang="scss" module>
.button {
--height: 21px;

position: relative;
display: inline-flex;
flex-shrink: 0;
margin: 0;
box-sizing: border-box;
width: 32px;
height: 23px;
width: calc(var(--height) * 1.6);
height: calc(var(--height) + 2px); // 枠線
outline: none;
background: var(--switchOffBg);
background-clip: content-box;
Expand All @@ -69,9 +71,10 @@ const toggle = () => {

.knob {
position: absolute;
box-sizing: border-box;
top: 3px;
width: 15px;
height: 15px;
width: calc(var(--height) - 6px);
height: calc(var(--height) - 6px);
border-radius: 999px;
transition: all 0.2s ease;

Expand All @@ -82,7 +85,7 @@ const toggle = () => {
}

.knobChecked {
left: 12px;
left: calc(calc(100% - var(--height)) + 3px);
background: var(--switchOnFg);
}
</style>
2 changes: 1 addition & 1 deletion packages/frontend/src/types/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type MenuLabel = { type: 'label', text: string };
export type MenuLink = { type: 'link', to: string, text: string, icon?: string, indicate?: boolean, avatar?: Misskey.entities.User };
export type MenuA = { type: 'a', href: string, target?: string, download?: string, text: string, icon?: string, indicate?: boolean };
export type MenuUser = { type: 'user', user: Misskey.entities.User, active?: boolean, indicate?: boolean, action: MenuAction };
export type MenuSwitch = { type: 'switch', ref: Ref<boolean>, text: string, disabled?: boolean | Ref<boolean> };
export type MenuSwitch = { type: 'switch', ref: Ref<boolean>, text: string, icon?: string, disabled?: boolean | Ref<boolean> };
export type MenuButton = { type?: 'button', text: string, icon?: string, indicate?: boolean, danger?: boolean, active?: boolean | ComputedRef<boolean>, avatar?: Misskey.entities.User; action: MenuAction };
export type MenuRadio = { type: 'radio', text: string, icon?: string, ref: Ref<MenuRadioOptionsDef[keyof MenuRadioOptionsDef]>, options: MenuRadioOptionsDef, disabled?: boolean | Ref<boolean> };
export type MenuRadioOption = { type: 'radioOption', text: string, action: MenuAction; active?: boolean | ComputedRef<boolean> };
Expand Down

0 comments on commit 024a9f4

Please sign in to comment.