updated to new files
This commit is contained in:
BIN
src/__pycache__/python_functions.cpython-311.pyc
Normal file
BIN
src/__pycache__/python_functions.cpython-311.pyc
Normal file
Binary file not shown.
@@ -1 +0,0 @@
|
|||||||
This file is intentionally left blank.
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
# This directory is intended to contain video files for the media player application.
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
<contents of /kivy-media-player/kivy-media-player/src/kv/main.kv>
|
|
||||||
|
|
||||||
<ScreenManager>:
|
|
||||||
MainScreen:
|
|
||||||
SettingsScreen:
|
|
||||||
|
|
||||||
<MainScreen>:
|
|
||||||
name: 'main'
|
|
||||||
BoxLayout:
|
|
||||||
orientation: 'vertical'
|
|
||||||
Label:
|
|
||||||
text: 'Welcome to the Media Player'
|
|
||||||
font_size: 32
|
|
||||||
size_hint_y: None
|
|
||||||
height: 50
|
|
||||||
Button:
|
|
||||||
text: 'Go to Settings'
|
|
||||||
on_press: root.manager.current = 'settings'
|
|
||||||
Button:
|
|
||||||
text: 'Play Media'
|
|
||||||
on_press: app.play_media()
|
|
||||||
|
|
||||||
<SettingsScreen>:
|
|
||||||
name: 'settings'
|
|
||||||
BoxLayout:
|
|
||||||
orientation: 'vertical'
|
|
||||||
Label:
|
|
||||||
text: 'Settings'
|
|
||||||
font_size: 32
|
|
||||||
size_hint_y: None
|
|
||||||
height: 50
|
|
||||||
TextInput:
|
|
||||||
id: quick_connect_code
|
|
||||||
hint_text: 'Enter Quick Connect Code'
|
|
||||||
multiline: False
|
|
||||||
TextInput:
|
|
||||||
id: server_ip
|
|
||||||
hint_text: 'Enter Server IP or Domain'
|
|
||||||
multiline: False
|
|
||||||
Button:
|
|
||||||
text: 'Save Settings'
|
|
||||||
on_press: app.save_settings(quick_connect_code.text, server_ip.text)
|
|
||||||
Button:
|
|
||||||
text: 'Back to Main'
|
|
||||||
on_press: root.manager.current = 'main'
|
|
||||||
@@ -1,52 +1,15 @@
|
|||||||
<contents of /kivy-media-player/kivy-media-player/src/kv/media_player.kv>
|
<MediaPlayer>:
|
||||||
|
video_player: video_player
|
||||||
|
image_display: image_display
|
||||||
|
|
||||||
<MediaPlayerScreen>:
|
Video:
|
||||||
name: 'media_player'
|
id: video_player
|
||||||
BoxLayout:
|
opacity: 0
|
||||||
orientation: 'vertical'
|
|
||||||
|
|
||||||
Video:
|
|
||||||
id: video_player
|
|
||||||
state: 'stop'
|
|
||||||
options: {'eos': 'stop'}
|
|
||||||
|
|
||||||
BoxLayout:
|
|
||||||
size_hint_y: None
|
|
||||||
height: '50dp'
|
|
||||||
Button:
|
|
||||||
text: 'Play'
|
|
||||||
on_press: root.play_video()
|
|
||||||
Button:
|
|
||||||
text: 'Pause'
|
|
||||||
on_press: root.pause_video()
|
|
||||||
Button:
|
|
||||||
text: 'Stop'
|
|
||||||
on_press: root.stop_video()
|
|
||||||
Button:
|
|
||||||
text: 'Next'
|
|
||||||
on_press: root.next_video()
|
|
||||||
|
|
||||||
Image:
|
|
||||||
id: image_display
|
|
||||||
allow_stretch: True
|
|
||||||
keep_ratio: True
|
|
||||||
size_hint_y: None
|
|
||||||
height: '300dp'
|
|
||||||
|
|
||||||
Label:
|
|
||||||
id: playlist_label
|
|
||||||
text: 'Playlist'
|
|
||||||
size_hint_y: None
|
|
||||||
height: '30dp'
|
|
||||||
|
|
||||||
ScrollView:
|
|
||||||
size_hint_y: None
|
|
||||||
height: '200dp'
|
|
||||||
GridLayout:
|
|
||||||
id: playlist
|
|
||||||
cols: 1
|
|
||||||
size_hint_y: None
|
|
||||||
height: self.minimum_height
|
|
||||||
|
|
||||||
<MediaPlayerScreen>:
|
Image:
|
||||||
on_enter: root.load_playlist()
|
id: image_display
|
||||||
|
allow_stretch: True
|
||||||
|
keep_ratio: True
|
||||||
|
size_hint: (1, 1)
|
||||||
|
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
|
||||||
|
opacity: 0
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
<settings.kv>
|
|
||||||
<SettingsScreen>:
|
|
||||||
BoxLayout:
|
|
||||||
orientation: 'vertical'
|
|
||||||
padding: 10
|
|
||||||
spacing: 10
|
|
||||||
|
|
||||||
Label:
|
|
||||||
text: 'Settings'
|
|
||||||
font_size: 24
|
|
||||||
size_hint_y: None
|
|
||||||
height: 40
|
|
||||||
|
|
||||||
Label:
|
|
||||||
text: 'Quick Connect Code:'
|
|
||||||
TextInput:
|
|
||||||
id: quick_connect_code
|
|
||||||
multiline: False
|
|
||||||
|
|
||||||
Label:
|
|
||||||
text: 'Server IP/Domain Name:'
|
|
||||||
TextInput:
|
|
||||||
id: server_ip
|
|
||||||
multiline: False
|
|
||||||
|
|
||||||
Button:
|
|
||||||
text: 'Save Settings'
|
|
||||||
on_press: app.save_settings(quick_connect_code.text, server_ip.text)
|
|
||||||
|
|
||||||
Button:
|
|
||||||
text: 'Back to Main'
|
|
||||||
on_press: app.change_screen('main')
|
|
||||||
21
src/main.py
21
src/main.py
@@ -1,21 +0,0 @@
|
|||||||
from kivy.app import App
|
|
||||||
from kivy.uix.screenmanager import ScreenManager, Screen
|
|
||||||
from kivy.clock import Clock
|
|
||||||
from settings import Settings
|
|
||||||
from media_player import MediaPlayer
|
|
||||||
|
|
||||||
class MainApp(App):
|
|
||||||
def build(self):
|
|
||||||
self.title = "Kivy Media Player"
|
|
||||||
self.sm = ScreenManager()
|
|
||||||
self.sm.add_widget(Settings(name='settings'))
|
|
||||||
self.sm.add_widget(MediaPlayer(name='media_player'))
|
|
||||||
Clock.schedule_interval(self.check_playlist_updates, 300) # Check for updates every 5 minutes
|
|
||||||
return self.sm
|
|
||||||
|
|
||||||
def check_playlist_updates(self, dt):
|
|
||||||
# Logic to check for updates in the playlist
|
|
||||||
pass
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
MainApp().run()
|
|
||||||
@@ -4,25 +4,22 @@ from kivy.clock import Clock
|
|||||||
from kivy.core.window import Window
|
from kivy.core.window import Window
|
||||||
from kivy.uix.video import Video
|
from kivy.uix.video import Video
|
||||||
from kivy.uix.image import Image
|
from kivy.uix.image import Image
|
||||||
from kivy.uix.boxlayout import BoxLayout
|
|
||||||
import requests
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
from kivy.config import Config
|
from kivy.config import Config
|
||||||
from kivy.logger import Logger
|
from kivy.logger import Logger
|
||||||
|
from kivy.lang import Builder
|
||||||
|
from python_functions import load_playlist, download_media_files
|
||||||
|
import os
|
||||||
|
|
||||||
Config.set('kivy', 'keyboard_mode', 'systemanddock')
|
Config.set('kivy', 'keyboard_mode', 'systemanddock')
|
||||||
|
|
||||||
|
# Load the KV file
|
||||||
|
Builder.load_file('kv/media_player.kv')
|
||||||
|
|
||||||
class MediaPlayer(Screen):
|
class MediaPlayer(Screen):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super(MediaPlayer, self).__init__(**kwargs)
|
super(MediaPlayer, self).__init__(**kwargs)
|
||||||
self.playlist = []
|
self.playlist = []
|
||||||
self.current_index = 0
|
self.current_index = 0
|
||||||
self.video_player = Video()
|
|
||||||
self.image_display = Image()
|
|
||||||
self.layout = BoxLayout(orientation='vertical')
|
|
||||||
self.layout.add_widget(self.video_player)
|
|
||||||
self.layout.add_widget(self.image_display)
|
|
||||||
self.add_widget(self.layout)
|
|
||||||
Clock.schedule_interval(self.check_playlist_updates, 300) # Check for updates every 5 minutes
|
Clock.schedule_interval(self.check_playlist_updates, 300) # Check for updates every 5 minutes
|
||||||
Window.bind(on_key_down=self.on_key_down)
|
Window.bind(on_key_down=self.on_key_down)
|
||||||
|
|
||||||
@@ -31,62 +28,10 @@ class MediaPlayer(Screen):
|
|||||||
Window.fullscreen = not Window.fullscreen
|
Window.fullscreen = not Window.fullscreen
|
||||||
|
|
||||||
def on_enter(self):
|
def on_enter(self):
|
||||||
self.load_playlist()
|
self.playlist = load_playlist()
|
||||||
self.download_media_files()
|
download_media_files(self.playlist)
|
||||||
self.play_media()
|
self.play_media()
|
||||||
|
|
||||||
def load_playlist(self):
|
|
||||||
# Load playlist from the server or local storage
|
|
||||||
try:
|
|
||||||
Logger.debug("Attempting to load playlist from server...")
|
|
||||||
server_ip = 'http://192.168.0.115:5000'
|
|
||||||
hostname = 'player1.local'
|
|
||||||
quickconnect_code = 'Initial01!'
|
|
||||||
url = f'{server_ip}/api/playlists'
|
|
||||||
params = {
|
|
||||||
'hostname': "TvHolBa1",
|
|
||||||
'quickconnect_code': quickconnect_code
|
|
||||||
}
|
|
||||||
response = requests.get(url, params=params)
|
|
||||||
|
|
||||||
# Print the raw response content and status code for debugging
|
|
||||||
Logger.debug(f'Status Code: {response.status_code}')
|
|
||||||
Logger.debug(f'Response Content: {response.text}')
|
|
||||||
|
|
||||||
# Check if the request was successful
|
|
||||||
if response.status_code == 200:
|
|
||||||
try:
|
|
||||||
# Parse the JSON response
|
|
||||||
self.playlist = response.json().get('playlist', [])
|
|
||||||
Logger.debug(f'Playlist: {self.playlist}')
|
|
||||||
except json.JSONDecodeError as e:
|
|
||||||
Logger.error(f'Failed to parse JSON response: {e}')
|
|
||||||
else:
|
|
||||||
Logger.error(f'Failed to retrieve playlist: {response.text}')
|
|
||||||
except requests.exceptions.RequestException as e:
|
|
||||||
Logger.error(f"Failed to load playlist: {e}")
|
|
||||||
|
|
||||||
def download_media_files(self):
|
|
||||||
base_dir = os.path.join(os.path.dirname(__file__), 'static', 'resurse') # Update this to the correct path
|
|
||||||
if not os.path.exists(base_dir):
|
|
||||||
os.makedirs(base_dir)
|
|
||||||
|
|
||||||
for media in self.playlist:
|
|
||||||
file_name = media.get('file_name', '')
|
|
||||||
file_url = f"http://192.168.0.115:5000/media/{file_name}" # Update this to the correct URL
|
|
||||||
file_path = os.path.join(base_dir, file_name)
|
|
||||||
|
|
||||||
try:
|
|
||||||
response = requests.get(file_url)
|
|
||||||
if response.status_code == 200:
|
|
||||||
with open(file_path, 'wb') as file:
|
|
||||||
file.write(response.content)
|
|
||||||
Logger.debug(f"Downloaded {file_name} to {file_path}")
|
|
||||||
else:
|
|
||||||
Logger.error(f"Failed to download {file_name}: {response.status_code}")
|
|
||||||
except requests.exceptions.RequestException as e:
|
|
||||||
Logger.error(f"Failed to download {file_name}: {e}")
|
|
||||||
|
|
||||||
def play_media(self):
|
def play_media(self):
|
||||||
if self.playlist:
|
if self.playlist:
|
||||||
media = self.playlist[self.current_index]
|
media = self.playlist[self.current_index]
|
||||||
@@ -100,11 +45,13 @@ class MediaPlayer(Screen):
|
|||||||
|
|
||||||
if file_extension in ['.mp4', '.avi', '.mov']:
|
if file_extension in ['.mp4', '.avi', '.mov']:
|
||||||
self.video_player.source = file_path
|
self.video_player.source = file_path
|
||||||
|
self.video_player.opacity = 1
|
||||||
self.video_player.play()
|
self.video_player.play()
|
||||||
self.image_display.source = ''
|
self.image_display.opacity = 0
|
||||||
elif file_extension in ['.jpg', '.jpeg', '.png', '.gif']:
|
elif file_extension in ['.jpg', '.jpeg', '.png', '.gif']:
|
||||||
self.image_display.source = file_path
|
self.image_display.source = file_path
|
||||||
self.video_player.source = ''
|
self.image_display.opacity = 1
|
||||||
|
self.video_player.opacity = 0
|
||||||
self.image_display.reload()
|
self.image_display.reload()
|
||||||
Clock.schedule_once(self.next_media, duration)
|
Clock.schedule_once(self.next_media, duration)
|
||||||
else:
|
else:
|
||||||
@@ -115,8 +62,8 @@ class MediaPlayer(Screen):
|
|||||||
self.play_media()
|
self.play_media()
|
||||||
|
|
||||||
def check_playlist_updates(self, dt):
|
def check_playlist_updates(self, dt):
|
||||||
self.load_playlist()
|
self.playlist = load_playlist()
|
||||||
self.download_media_files()
|
download_media_files(self.playlist)
|
||||||
self.play_media()
|
self.play_media()
|
||||||
|
|
||||||
class MediaPlayerApp(App):
|
class MediaPlayerApp(App):
|
||||||
|
|||||||
58
src/python_functions.py
Normal file
58
src/python_functions.py
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import requests
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
from kivy.logger import Logger
|
||||||
|
|
||||||
|
def load_playlist():
|
||||||
|
# Load playlist from the server or local storage
|
||||||
|
try:
|
||||||
|
Logger.debug("Attempting to load playlist from server...")
|
||||||
|
server_ip = 'http://192.168.0.115:5000'
|
||||||
|
hostname = 'TvHolBa1'
|
||||||
|
quickconnect_code = 'Initial01!'
|
||||||
|
url = f'{server_ip}/api/playlists'
|
||||||
|
params = {
|
||||||
|
'hostname': hostname,
|
||||||
|
'quickconnect_code': quickconnect_code
|
||||||
|
}
|
||||||
|
response = requests.get(url, params=params)
|
||||||
|
|
||||||
|
# Print the raw response content and status code for debugging
|
||||||
|
Logger.debug(f'Status Code: {response.status_code}')
|
||||||
|
Logger.debug(f'Response Content: {response.text}')
|
||||||
|
|
||||||
|
# Check if the request was successful
|
||||||
|
if response.status_code == 200:
|
||||||
|
try:
|
||||||
|
# Parse the JSON response
|
||||||
|
playlist = response.json().get('playlist', [])
|
||||||
|
Logger.debug(f'Playlist: {playlist}')
|
||||||
|
return playlist
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
Logger.error(f'Failed to parse JSON response: {e}')
|
||||||
|
else:
|
||||||
|
Logger.error(f'Failed to retrieve playlist: {response.text}')
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
Logger.error(f"Failed to load playlist: {e}")
|
||||||
|
return []
|
||||||
|
|
||||||
|
def download_media_files(playlist):
|
||||||
|
base_dir = os.path.join(os.path.dirname(__file__), 'static', 'resurse') # Update this to the correct path
|
||||||
|
if not os.path.exists(base_dir):
|
||||||
|
os.makedirs(base_dir)
|
||||||
|
|
||||||
|
for media in playlist:
|
||||||
|
file_name = media.get('file_name', '')
|
||||||
|
file_url = media.get('url', '')
|
||||||
|
file_path = os.path.join(base_dir, file_name)
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = requests.get(file_url)
|
||||||
|
if response.status_code == 200:
|
||||||
|
with open(file_path, 'wb') as file:
|
||||||
|
file.write(response.content)
|
||||||
|
Logger.debug(f"Downloaded {file_name} to {file_path}")
|
||||||
|
else:
|
||||||
|
Logger.error(f"Failed to download {file_name}: {response.status_code}")
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
Logger.error(f"Failed to download {file_name}: {e}")
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
from kivy.app import App
|
|
||||||
from kivy.uix.screenmanager import Screen
|
|
||||||
from kivy.uix.boxlayout import BoxLayout
|
|
||||||
from kivy.uix.label import Label
|
|
||||||
from kivy.uix.textinput import TextInput
|
|
||||||
from kivy.uix.button import Button
|
|
||||||
from kivy.properties import StringProperty
|
|
||||||
from kivy.storage.jsonstore import JsonStore
|
|
||||||
|
|
||||||
class Settings(Screen):
|
|
||||||
quick_connect_code = StringProperty("")
|
|
||||||
server_ip = StringProperty("")
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
super(Settings, self).__init__(**kwargs)
|
|
||||||
self.store = JsonStore('settings.json')
|
|
||||||
self.load_settings()
|
|
||||||
|
|
||||||
self.layout = BoxLayout(orientation='vertical')
|
|
||||||
|
|
||||||
self.server_ip_input = TextInput(hint_text='Server IP or Domain')
|
|
||||||
self.quick_connect_code_input = TextInput(hint_text='Quick Connect Code')
|
|
||||||
|
|
||||||
self.layout.add_widget(Label(text='Server IP or Domain:'))
|
|
||||||
self.layout.add_widget(self.server_ip_input)
|
|
||||||
self.layout.add_widget(Label(text='Quick Connect Code:'))
|
|
||||||
self.layout.add_widget(self.quick_connect_code_input)
|
|
||||||
|
|
||||||
self.save_button = Button(text='Save', on_press=self.save_settings)
|
|
||||||
self.layout.add_widget(self.save_button)
|
|
||||||
|
|
||||||
self.add_widget(self.layout)
|
|
||||||
|
|
||||||
def load_settings(self):
|
|
||||||
if self.store.exists('settings'):
|
|
||||||
settings = self.store.get('settings')
|
|
||||||
self.quick_connect_code = settings.get('quick_connect_code', "")
|
|
||||||
self.server_ip = settings.get('server_ip', "")
|
|
||||||
|
|
||||||
def save_settings(self, instance=None):
|
|
||||||
self.store.put('settings', quick_connect_code=self.quick_connect_code, server_ip=self.server_ip)
|
|
||||||
server_ip = self.server_ip_input.text
|
|
||||||
quick_connect_code = self.quick_connect_code_input.text
|
|
||||||
# Save the settings (e.g., to a file or database)
|
|
||||||
print(f'Settings saved: Server IP = {server_ip}, Quick Connect Code = {quick_connect_code}')
|
|
||||||
|
|
||||||
def on_quick_connect_code(self, instance, value):
|
|
||||||
self.save_settings()
|
|
||||||
|
|
||||||
def on_server_ip(self, instance, value):
|
|
||||||
self.save_settings()
|
|
||||||
BIN
src/static/resurse/car_modular.jpg
Normal file
BIN
src/static/resurse/car_modular.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 146 KiB |
BIN
src/static/resurse/harting_contact_2.jpg
Normal file
BIN
src/static/resurse/harting_contact_2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 312 KiB |
29
src/utils.py
29
src/utils.py
@@ -1,29 +0,0 @@
|
|||||||
def download_file(url, destination):
|
|
||||||
import requests
|
|
||||||
response = requests.get(url)
|
|
||||||
if response.status_code == 200:
|
|
||||||
with open(destination, 'wb') as f:
|
|
||||||
f.write(response.content)
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def check_for_playlist_updates(playlist_url, current_playlist):
|
|
||||||
import requests
|
|
||||||
response = requests.get(playlist_url)
|
|
||||||
if response.status_code == 200:
|
|
||||||
new_playlist = response.json()
|
|
||||||
if new_playlist != current_playlist:
|
|
||||||
return new_playlist
|
|
||||||
return None
|
|
||||||
|
|
||||||
def schedule_playlist_update(playlist_url, current_playlist, update_interval=300):
|
|
||||||
from threading import Timer
|
|
||||||
|
|
||||||
def check_updates():
|
|
||||||
new_playlist = check_for_playlist_updates(playlist_url, current_playlist)
|
|
||||||
if new_playlist:
|
|
||||||
current_playlist.clear()
|
|
||||||
current_playlist.extend(new_playlist)
|
|
||||||
Timer(update_interval, check_updates).start()
|
|
||||||
|
|
||||||
check_updates()
|
|
||||||
Reference in New Issue
Block a user