### FeelUOwn 更新贴
[FeelUOwn](
https://github.com/cosven/FeelUOwn) 是一款为 Linux 专门开发的音乐软件。目前相当于一个第三方版的网易云音乐。`Python` `Qt` `Linux`
旧贴 <
http://v2ex.com/t/235214#reply33>
- 新增加了歌单缓存,歌曲信息缓存。
- 修复一些已知的 bug
歌曲缓存指日可待... `哭笑脸`
> 对网速不好的朋友来说应该是个好消息.....
截图来一发:
![v5.0alpha 截图](
http://7xnn7w.com1.z0.glb.clouddn.com/v5.0a.png)
最后附一段 Python + PyQt5 边缓存边听歌的解决方案 demo 版: (也是费劲苦心... Google 都被我用坏了,最后终于写了个 demo)
```
#! /usr/bin/env python3
import sys
import time
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtMultimedia import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from _thread import start_new_thread
from threading import Thread, RLock
import requests
import os
# secret base
mp3_url = '
http://m1.music.126.net/Gybpf5bX9zfNesjXxZl3qw==/2053887720715417.mp3'# chedan
mp3_url = '
http://m2.music.126.net/7tEJKStKIbxKPVKw7urYkA==/6033020302257380.mp3'# liangzhu
mp3_url = '
http://m2.music.126.net/Jx2_zeePijuCGjqGSgTGyw==/6656443395918618.mp3'global i
i = 0
def print_duration(duration):
time_text = QTime(0, (duration / 60000) % 60, (duration/ 1000) % 60)
print("duration:", time_text.toString("mm:ss"))
def print_position(position):
time_text = QTime(0, (position/ 60000) % 60, (position/ 1000) % 60)
print('position:', time_text.toString("mm:ss"), i)
def print_media_changed(media):
print ("media changed")
def print_buffer(status):
print ('buffer', status)
class QFileWithLock(QFile):
def __init__(self, path):
super().__init__(path)
self.lock = RLock()
self.use_lock = True
def disable_lock(self):
self.use_lock = False
def enable_lock(self):
self.use_lock = True
def seek(self, pos):
if self.use_lock:
print('use lock')
self.lock.acquire()
flag = super().seek(pos)
self.lock.release()
else:
flag = super().seek(pos)
return flag
def write_to_end(self, data):
print ('write_to_end wait for lock')
self.lock.acquire()
print ('get lock')
super().seek(self.size())
data = super().write(data)
self.lock.release()
return data
class Player(QObject):
def __init__(self):
super().__init__()
self.player = QMediaPlayer(flags=QMediaPlayer.StreamPlayback)
# self.player.positionChanged.connect(print_position)
self.player.durationChanged.connect(print_duration)
self.player.currentMediaChanged.connect(print_media_changed)
self.player.bufferStatusChanged.connect(print_buffer)
self.tmp_pos = 0
def start(self):
print('start')
start_new_thread(self.async, ())
time.sleep(2)
self.player.setMedia(QMediaContent(), self.music)
self.player.play()
def async(self):
global i
self.res = requests.get(mp3_url, stream=True, timeout=1)
self.music = QFileWithLock('temp.mp3')
# self.music = QBuffer()
flag = self.music.open(QIODevice.ReadWrite)
for chunk in self.res.iter_content(1024000):
print('i:', i, end='')
self.player.pause()
print ('file seek pos: ', self.music.pos(), end='')
# self.music.seek(self.music.size())
# self.music.write(chunk)
self.music.write_to_end(chunk)
print ('file seek pos: ', self.music.pos())
self.player.play()
i += 1
print("finished")
self.music.disable_lock()
class Widget(QWidget):
def __init__(self):
super().__init__()
self.player = Player()
self.button = QPushButton('play', self)
self.button.clicked.connect(self.player.start)
app = QtWidgets.QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())
```
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.