-{this.state.leftTime}
@@ -78,7 +80,7 @@ let Player = React.createClass({
@@ -88,15 +90,15 @@ let Player = React.createClass({
-
-
-
+
+
+
@@ -104,12 +106,12 @@ let Player = React.createClass({
-

+
);
}
-});
+}
export default Player;
diff --git a/app/final/page/player.less b/app/page/player.less
old mode 100644
new mode 100755
similarity index 66%
rename from app/final/page/player.less
rename to app/page/player.less
index 979b1fd..6d81d66
--- a/app/final/page/player.less
+++ b/app/page/player.less
@@ -17,6 +17,18 @@
width: 180px;
height: 180px;
border-radius: 50%;
+ animation: rotation 10s linear infinite;
+ -webkit-animation: rotation 10s linear infinite;
+
+ &.playing {
+ -webkit-animation-play-state: running;
+ animation-play-state: running;
+ }
+
+ &.pausing {
+ -webkit-animation-play-state: paused;
+ animation-play-state: paused;
+ }
}
}
.volume-container {
@@ -61,5 +73,13 @@
.volume-wrapper {
width: 60px;
display: inline-block;
- }
+ }
+ @keyframes rotation{
+ from {transform: rotate(0deg);}
+ to {transform: rotate(360deg);}
+ }
+ @-webkit-keyframes rotation{
+ from {-webkit-transform: rotate(0deg);}
+ to {-webkit-transform: rotate(360deg);}
+ }
}
\ No newline at end of file
diff --git a/app/playmusic/Root.js b/app/playmusic/Root.js
deleted file mode 100644
index 8af99e2..0000000
--- a/app/playmusic/Root.js
+++ /dev/null
@@ -1,49 +0,0 @@
-import React from 'react';
-import Progress from './components/progress';
-
-let Root = React.createClass({
- componentDidMount() {
- $("#player").jPlayer({
- ready: function () {
- $(this).jPlayer("setMedia", {
- mp3: "http://oj4t8z2d5.bkt.clouddn.com/%E9%AD%94%E9%AC%BC%E4%B8%AD%E7%9A%84%E5%A4%A9%E4%BD%BF.mp3"
- }).jPlayer('play');
- },
- supplied: "mp3",
- wmode: "window",
- useStateClassSkin: true
- });
- $("#player").bind($.jPlayer.event.timeupdate, (e) => {
- this.setState({
- progress: Math.round(e.jPlayer.status.currentTime)
- });
- });
- },
- componentWillUnmout() {
- $("#player").unbind($.jPlayer.event.timeupdate);
- },
- getInitialState() {
- return {
- progress: 0
- }
- },
- counterHandler() {
- this.setState({
- count: this.state.count + 1
- });
- },
- render() {
- return (
-
-
Welcome to the React lesson~
-
Let us play music
-
-
- );
- }
-});
-
-export default Root;
diff --git a/app/playmusic/components/progress.js b/app/playmusic/components/progress.js
deleted file mode 100644
index 0c7ca20..0000000
--- a/app/playmusic/components/progress.js
+++ /dev/null
@@ -1,13 +0,0 @@
-import React from 'react';
-
-let Progress = React.createClass({
- render() {
- return (
-
- 已播放:{this.props.progress}s
-
- );
- }
-});
-
-export default Progress;
diff --git a/app/playmusic/index.js b/app/playmusic/index.js
deleted file mode 100644
index ef6f229..0000000
--- a/app/playmusic/index.js
+++ /dev/null
@@ -1,24 +0,0 @@
-import React from 'react';
-import { render } from 'react-dom';
-import { AppContainer } from 'react-hot-loader';
-import Root from './Root';
-
-
-render(
-
-
- ,
- document.getElementById('root')
-);
-
-if (module.hot) {
- module.hot.accept('./Root', () => {
- const NewRoot = require('./Root').default;
- render(
-
-
- ,
- document.getElementById('root')
- );
- });
-}
diff --git a/app/final/Root.js b/app/root.js
similarity index 67%
rename from app/final/Root.js
rename to app/root.js
index 7f2baa0..b4fdb68 100644
--- a/app/final/Root.js
+++ b/app/root.js
@@ -1,16 +1,24 @@
-import React, { render } from 'react';
-import { Router, IndexRoute, Link, Route, browserHistory, hashHistory} from 'react-router';
+import React from 'react';
+import { HashRouter, Route, Switch } from 'react-router-dom';
import { MUSIC_LIST } from './config/config';
import { randomRange } from './utils/util';
-let PubSub = require('pubsub-js');
+import PubSub from 'pubsub-js';
-import PlayerPage from './page/player';
-import listPage from './page/list';
-import Logo from './components/logo'
+import Header from './components/header';
+import Player from './page/player';
+import List from './page/list';
+class Root extends React.Component {
+ constructor(props) {
+ super(props);
-let App = React.createClass({
- componentDidMount() {
+ this.state = {
+ musicList: MUSIC_LIST,
+ currentMusitItem: {},
+ repeatType: 'cycle'
+ }
+ }
+ componentDidMount() {
$("#player").jPlayer({
supplied: "mp3",
wmode: "window",
@@ -50,21 +58,14 @@ let App = React.createClass({
repeatType: repeatList[index]
});
});
- },
+ }
componentWillUnmount() {
PubSub.unsubscribe('PLAY_MUSIC');
PubSub.unsubscribe('DEL_MUSIC');
PubSub.unsubscribe('CHANAGE_REPEAT');
PubSub.unsubscribe('PLAY_NEXT');
PubSub.unsubscribe('PLAY_PREV');
- },
- getInitialState() {
- return {
- musicList: MUSIC_LIST,
- currentMusitItem: {},
- repeatType: 'cycle'
- }
- },
+ }
playWhenEnd() {
if (this.state.repeatType === 'random') {
let index = this.findMusicIndex(this.state.currentMusitItem);
@@ -78,7 +79,7 @@ let App = React.createClass({
} else {
this.playNext();
}
- },
+ }
playNext(type = 'next') {
let index = this.findMusicIndex(this.state.currentMusitItem);
if (type === 'next') {
@@ -91,11 +92,11 @@ let App = React.createClass({
currentMusitItem: musicItem
});
this.playMusic(musicItem);
- },
+ }
findMusicIndex(music) {
let index = this.state.musicList.indexOf(music);
return Math.max(0, index);
- },
+ }
playMusic(item) {
$("#player").jPlayer("setMedia", {
mp3: item.file
@@ -103,28 +104,37 @@ let App = React.createClass({
this.setState({
currentMusitItem: item
});
- },
+ }
render() {
+ let value = this.state;
+
+ const Home = () => (
+
+ );
+
+ const musicList = () => (
+
+ );
+
return (
-
-
- {React.cloneElement(this.props.children, this.state)}
-
+
+
+
+
+
+
+
+
+
+
);
}
-});
-
-let Root = React.createClass({
- render() {
- return (
-
-
-
-
-
-
- );
- }
-});
+}
-export default Root;
+export default Root;
\ No newline at end of file
diff --git a/app/router/Root.js b/app/router/Root.js
deleted file mode 100644
index 87ba954..0000000
--- a/app/router/Root.js
+++ /dev/null
@@ -1,71 +0,0 @@
-import React, { render } from 'react';
-import { Router, IndexRoute, Link, Route, browserHistory, hashHistory} from 'react-router';
-import { MUSIC_LIST } from './config/config';
-let PubSub = require('pubsub-js');
-
-import PlayerPage from './page/player';
-import listPage from './page/list';
-import Logo from './components/logo'
-
-
-let App = React.createClass({
- componentDidMount() {
- $("#player").jPlayer({
- supplied: "mp3",
- wmode: "window",
- useStateClassSkin: true
- });
- this.playMusic(MUSIC_LIST[0]);
- PubSub.subscribe('PLAY_MUSIC', (msg, item) => {
- this.playMusic(item);
- });
- PubSub.subscribe('DEL_MUSIC', (msg, item) => {
- this.setState({
- musicList: this.state.musicList.filter((music) => {
- return music !== item;
- })
- });
- });
- },
- componentWillUnmount() {
- PubSub.unsubscribe('PLAY_MUSIC');
- PubSub.unsubscribe('DEL_MUSIC');
- },
- getInitialState() {
- return {
- musicList: MUSIC_LIST,
- currentMusitItem: {}
- }
- },
- playMusic(item) {
- $("#player").jPlayer("setMedia", {
- mp3: item.file
- }).jPlayer('play');
- this.setState({
- currentMusitItem: item
- });
- },
- render() {
- return (
-
-
- {React.cloneElement(this.props.children, {musicList: this.state.musicList, currentMusitItem: this.state.currentMusitItem})}
-
- );
- }
-});
-
-let Root = React.createClass({
- render() {
- return (
-
-
-
-
-
-
- );
- }
-});
-
-export default Root;
diff --git a/app/router/components/listItem.js b/app/router/components/listItem.js
deleted file mode 100644
index 381f9f7..0000000
--- a/app/router/components/listItem.js
+++ /dev/null
@@ -1,24 +0,0 @@
-import React from 'react';
-require('./listitem.less');
-let PubSub = require('pubsub-js');
-
-let ListItem = React.createClass({
- deleteHandler(item, event) {
- event.stopPropagation();
- PubSub.publish('DEL_MUSIC', item);
- },
- playMusic(item, e) {
- PubSub.publish('PLAY_MUSIC', item);
- },
- render() {
- let item = this.props.data;
- return (
-
- {item.title} - {item.artist}
-
-
- );
- }
-});
-
-export default ListItem;
diff --git a/app/router/components/listitem.less b/app/router/components/listitem.less
deleted file mode 100644
index fab08f1..0000000
--- a/app/router/components/listitem.less
+++ /dev/null
@@ -1,37 +0,0 @@
-.components-listitem {
- height: 36px;
- line-height: 36px;
- border-bottom: 1px solid #ddd;
- text-indent: 10px;
- cursor: pointer;
- .delete {
- cursor: pointer;
- height: 30px;
- width: 30px;
- top: 3px;
- position: relative;
- transform: rotate(45deg);
- margin-right: 15px;
- &::before, &::after{
- content: '';
- display: block;
- background: #666;
- position: absolute;
- }
- &::before {
- width: 100%;
- height: 1px;
- top: 14px;
- left: 0;
- }
- &::after {
- height: 100%;
- width: 1px;
- left: 15px;
- top: 0;
- }
- }
-}
-.components-listitem:hover {
- background: #eee;
-}
\ No newline at end of file
diff --git a/app/router/components/logo.js b/app/router/components/logo.js
deleted file mode 100644
index 4fe731b..0000000
--- a/app/router/components/logo.js
+++ /dev/null
@@ -1,15 +0,0 @@
-import React from 'react';
-require('./logo.less');
-
-let Logo = React.createClass({
- render() {
- return (
-
-

-
Music Player Build By React
-
- );
- }
-});
-
-export default Logo;
diff --git a/app/router/components/logo.less b/app/router/components/logo.less
deleted file mode 100644
index 44f516d..0000000
--- a/app/router/components/logo.less
+++ /dev/null
@@ -1,6 +0,0 @@
-.components-logo {
- .caption {
- font-size: 20px;
- text-indent: 20px;
- }
-}
\ No newline at end of file
diff --git a/app/router/components/progress.js b/app/router/components/progress.js
deleted file mode 100644
index 0c7ca20..0000000
--- a/app/router/components/progress.js
+++ /dev/null
@@ -1,13 +0,0 @@
-import React from 'react';
-
-let Progress = React.createClass({
- render() {
- return (
-
- 已播放:{this.props.progress}s
-
- );
- }
-});
-
-export default Progress;
diff --git a/app/router/config/config.js b/app/router/config/config.js
deleted file mode 100644
index 287e023..0000000
--- a/app/router/config/config.js
+++ /dev/null
@@ -1,40 +0,0 @@
-export const MUSIC_LIST = [
- {
- id: 1,
- title: '天使中的魔鬼',
- artist: '田馥甄',
- file: 'http://oj4t8z2d5.bkt.clouddn.com/%E9%AD%94%E9%AC%BC%E4%B8%AD%E7%9A%84%E5%A4%A9%E4%BD%BF.mp3',
- cover: 'http://oj4t8z2d5.bkt.clouddn.com/%E9%AD%94%E9%AC%BC%E4%B8%AD%E7%9A%84%E5%A4%A9%E4%BD%BF.jpg'
- }, {
- id: 2,
- title: '风继续吹',
- artist: '张国荣',
- file: 'http://oj4t8z2d5.bkt.clouddn.com/%E9%A3%8E%E7%BB%A7%E7%BB%AD%E5%90%B9.mp3',
- cover: 'http://oj4t8z2d5.bkt.clouddn.com/%E9%A3%8E%E7%BB%A7%E7%BB%AD%E5%90%B9.jpg'
- }, {
- id: 3,
- title: '恋恋风尘',
- artist: '老狼',
- file: 'http://oj4t8z2d5.bkt.clouddn.com/%E6%81%8B%E6%81%8B%E9%A3%8E%E5%B0%98.mp3',
- cover: 'http://oj4t8z2d5.bkt.clouddn.com/%E6%81%8B%E6%81%8B%E9%A3%8E%E5%B0%98.jpg'
- }, {
- id: 4,
- title: '我要你',
- artist: '任素汐',
- file: 'http://oj4t8z2d5.bkt.clouddn.com/%E6%88%91%E8%A6%81%E4%BD%A0.mp3',
- cover: 'http://oj4t8z2d5.bkt.clouddn.com/%E6%88%91%E8%A6%81%E4%BD%A0.jpg'
- }, {
- id: 5,
- title: '成都',
- artist: '赵雷',
- file: 'http://oj4t8z2d5.bkt.clouddn.com/%E6%88%90%E9%83%BD.mp3',
- cover: 'http://oj4t8z2d5.bkt.clouddn.com/%E6%88%90%E9%83%BD.jpg'
- }, {
- id: 6,
- title: 'sound of silence',
- artist: 'Simon & Garfunkel',
- file: 'http://oj4t8z2d5.bkt.clouddn.com/sound-of-silence.mp3',
- cover: 'http://oj4t8z2d5.bkt.clouddn.com/sound-of-silence.jpg'
- }
-
-];
diff --git a/app/router/index.js b/app/router/index.js
deleted file mode 100644
index ef6f229..0000000
--- a/app/router/index.js
+++ /dev/null
@@ -1,24 +0,0 @@
-import React from 'react';
-import { render } from 'react-dom';
-import { AppContainer } from 'react-hot-loader';
-import Root from './Root';
-
-
-render(
-
-
- ,
- document.getElementById('root')
-);
-
-if (module.hot) {
- module.hot.accept('./Root', () => {
- const NewRoot = require('./Root').default;
- render(
-
-
- ,
- document.getElementById('root')
- );
- });
-}
diff --git a/app/router/page/list.js b/app/router/page/list.js
deleted file mode 100644
index 8dcbe30..0000000
--- a/app/router/page/list.js
+++ /dev/null
@@ -1,23 +0,0 @@
-import React from 'react';
-import { MUSIC_LIST } from '../config/config';
-import ListItem from '../components/listitem';
-
-let List = React.createClass({
- render() {
- let Items = this.props.musicList.map((item) => {
- return (
-
- );
- });
- return (
-
- );
- }
-});
-
-export default List;
diff --git a/app/router/page/player.js b/app/router/page/player.js
deleted file mode 100644
index e1c5572..0000000
--- a/app/router/page/player.js
+++ /dev/null
@@ -1,38 +0,0 @@
-import React from 'react';
-import Progress from '../components/progress';
-import { Link } from 'react-router';
-
-let Player = React.createClass({
- componentDidMount() {
- $("#player").bind($.jPlayer.event.timeupdate, (e) => {
- this.setState({
- progress: Math.round(e.jPlayer.status.currentTime)
- });
- });
- },
- componentWillUnmount() {
- $("#player").unbind($.jPlayer.event.timeupdate);
- },
- getInitialState() {
- return {
- progress: 0
- }
- },
- render() {
- return (
-
-
Welcome to the React lesson~
-
See my music list
-
{this.props.currentMusitItem.title} 播放中...
-
-
- );
- }
-});
-
-export default Player;
diff --git a/app/final/utils/util.js b/app/utils/util.js
old mode 100644
new mode 100755
similarity index 100%
rename from app/final/utils/util.js
rename to app/utils/util.js
diff --git a/package.json b/package.json
index 11aa431..301106b 100644
--- a/package.json
+++ b/package.json
@@ -1,8 +1,8 @@
{
- "name": "react-music-player",
+ "name": "react-music-palyer",
"version": "1.0.0",
- "description": "music player build with react, redux and react-router with the help of webpack.",
- "main": "index.js",
+ "description": "music player build by react",
+ "main": "app/index.js",
"scripts": {
"test": "",
"start": "node server",
@@ -10,38 +10,36 @@
"eslint": "eslint ."
},
"keywords": [
- "es6",
+ "webpack",
"react",
- "redux"
+ "music-player"
],
- "author": "musiq",
+ "author": "haibao",
"license": "MIT",
- "repository": {
- "type": "git",
- "url": "git+https://github.com/xiaolin3303/react-music-player"
- },
"dependencies": {
- "pubsub-js": "^1.5.4",
- "react": "^15.0.2",
- "react-dom": "^15.0.2",
- "react-hot-loader": "^3.0.0-beta.2",
- "react-router": "^2.0.0"
+ "pubsub-js": "^1.5.7",
+ "react": "^16.0.0",
+ "react-dom": "^16.0.0",
+ "react-hot-loader": "^3.1.1",
+ "react-router": "^4.2.0",
+ "react-router-dom": "^4.2.2"
},
"devDependencies": {
- "autoprefixer": "^6.3.6",
- "babel-core": "^6.5.2",
- "babel-loader": "^6.2.2",
- "babel-plugin-react-transform": "^2.0.0",
- "babel-preset-es2015": "^6.5.0",
- "babel-preset-react": "^6.5.0",
- "css-loader": "^0.23.1",
- "extract-text-webpack-plugin": "^1.0.1",
- "html-webpack-plugin": "^2.16.1",
- "json-loader": "^0.5.4",
- "less": "^2.6.0",
- "less-loader": "^2.2.2",
- "style-loader": "^0.13.1",
- "webpack": "^1.13.0",
- "webpack-dev-server": "^1.14.1"
+ "autoprefixer": "^7.1.6",
+ "babel-core": "^6.26.0",
+ "babel-loader": "^7.1.2",
+ "babel-plugin-react-transform": "^3.0.0",
+ "babel-preset-es2015": "^6.24.1",
+ "babel-preset-react": "^6.24.1",
+ "css-loader": "^0.28.7",
+ "extract-text-webpack-plugin": "^3.0.1",
+ "html-webpack-plugin": "^2.30.1",
+ "json-loader": "^0.5.7",
+ "less": "^2.7.3",
+ "less-loader": "^4.0.5",
+ "path": "^0.12.7",
+ "style-loader": "^0.19.0",
+ "webpack": "^3.8.1",
+ "webpack-dev-server": "^2.9.3"
}
}
diff --git a/webpack.config.js b/webpack.config.js
old mode 100644
new mode 100755
index 3399468..9f34477
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -10,7 +10,7 @@ module.exports = {
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'react-hot-loader/patch',
- path.join(__dirname, 'app/final/index.js')
+ path.join(__dirname, 'app/index.js')
],
output: {
path: path.join(__dirname, '/dist/'),
@@ -23,18 +23,15 @@ module.exports = {
inject: 'body',
filename: './index.html'
}),
- new webpack.optimize.OccurenceOrderPlugin(),
+ new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
- new webpack.NoErrorsPlugin(),
+ new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
})
],
- module: {
- resolve:{
- extensions:['','.js','.json']
- },
- loaders: [
+ module: {
+ rules: [
{
test: /\.js$/,
exclude: /node_modules/,
diff --git a/webpack.production.config.js b/webpack.production.config.js
old mode 100644
new mode 100755
index 473de87..038dd07
--- a/webpack.production.config.js
+++ b/webpack.production.config.js
@@ -5,9 +5,9 @@ var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
- // The entry file. All your app roots fromn here.
+ // The entry file. All your app roots from here.
entry: [
- path.join(__dirname, 'app/final/index.js')
+ path.join(__dirname, 'app/index.js')
],
// Where you want the output to go
output: {
@@ -19,7 +19,7 @@ module.exports = {
// webpack gives your modules and chunks ids to identify them. Webpack can vary the
// distribution of the ids to get the smallest id length for often used ids with
// this plugin
- new webpack.optimize.OccurenceOrderPlugin(),
+ new webpack.optimize.OccurrenceOrderPlugin(),
// handles creating an index.html file and injecting assets. necessary because assets
// change name because the hash part changes. We want hash name changes to bust cache
@@ -66,8 +66,5 @@ module.exports = {
loader: 'style-loader!css-loader!less-loader'
}
]
- },
- postcss: [
- require('autoprefixer')
- ]
+ }
};